【问题标题】:Script in a page, stopped working while Including content from other page with different script页面中的脚本,在使用不同脚本包含来自其他页面的内容时停止工作
【发布时间】:2015-12-03 18:36:02
【问题描述】:

我正在使用 Laravel 5 。 我正在尝试使用以下方法在页面中包含不同的内容:

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

我包含的每个页面都有自己的脚本。

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

在浏览包含所有内容页面的 页面时,只有 example_page_content_two 页面中的脚本有效,其他脚本 都在 >parentexample_page_content_one 不起作用。

我在 parent 页面中扩展 master.blade.php。 在我使用的母版页中

@yield('script')

有什么方法可以在不使用不同的 section 名称的情况下解决这个问题。 即

example_page_content_one

@section('scriptExampleOne')@endsection

example_page_content_two

@section('scriptExampleTwo')@endsection

在主刀片中

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

【问题讨论】:

    标签: javascript laravel include


    【解决方案1】:

    您需要使用@append 来结束您的脚本。如果您使用@endsection,那么它将覆盖之前添加的任何内容。

    所以:

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

    【讨论】:

    • 它适用于脚本!!当我在主要内容中尝试此操作时,仅显示最后一个 @included 页面的内容。如何解决?
    • 我不确定我是否理解。如果您使用的是@include,那么内容不需要@section,只有当您需要将某些内容添加到与您所包含的位置不同的部分时——如果这有意义的话。
    猜你喜欢
    • 1970-01-01
    • 2020-08-26
    • 1970-01-01
    • 2011-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-05
    相关资源
    最近更新 更多