shuvrow shuvrow - 1 month ago 10
Javascript Question

Script in a page, stoped working while Including content from other page with different script

I am using Laravel 5 .
I am trying to include different content in a page using:

@include('example_page_content_one')
@include('example_page_content_two')


Every page i am including has its own script.

@section('script')
<script>
</script>
@endsection


While browsing parent page, where all content pages were included, only script in example_page_content_two page is working and other scripts both in parent and example_page_content_one are not working.

I am extending
master.blade.php
in parent page.
In master page i used

@yield('script')


Is there any way to solve this without using different section name.
i.e

In example_page_content_one

@section('scriptExampleOne')@endsection


In example_page_content_two

@section('scriptExampleTwo')@endsection


In master blade

@yield('scriptExampleOne')
@yield('scriptExampleTwo')

Answer

You need to use the @append to end your script. If you use @endsection then it will overwrite any previously added content.

So:

@section('script')
     <script>
     </script>
@append