2017-06-21 156 views
1

我只需要在一个页面上使用脚本。它应该在jQuery之后加载。 我试着在index.blade如何在刀片模板中使用指令@push laravel

<script type="text/javascript" src="{{ URL::asset ('js/jquery.js') }}"></script> 
@push('custom-scripts') 
    <script type="text/javascript" src="{{ URL::asset ('js/custom-scripts.js') }}"></script> 
@endpush 

,然后我应该使用@stack(“自定义脚本”)我认为?

+0

是的,这是如何使用推和堆栈。它不工作? –

+0

@DavidHallbergJönsson,不工作。在index.blade(主视图)中我包含了所有的js。像 ' @push('custom-scripts') @endpush ' 然后在子视图中我写了 '@stack('custom-scripts')' – kuka

回答

1

你只需要使相反的方式,@push意味着在视图,这是推送内容到父@stash指令。

所以你index.blade.php应该有一个:

@stack('custom-scripts') 

和您的孩子的看法:

@push('custom-scripts') 
    <script type="text/javascript" src="{{ URL::asset ('js/custom-scripts.js') }}"></script> 
@endpush 

您还可以使用@parent指令与@section这样的:

//index.blade.php 
@yield('scripts') 


//child.blade.php 
@section('scripts') 
    @parent 
    <!-- The rest of your scripts --> 
@endsection 

如果您需要更多信息,我建议您检查documentation。希望这对你有所帮助。

+0

是的。我了解它。谢谢! – kuka

+0

@kuka不客气:) – Asur