问题:
I installed https://github.com/farbelous/bootstrap-colorpicker plugin to my laravel 5.7 / Bootstrap v4.1. / Jquery 3 / Blade application and question is which is the correc...
可以将文章内容翻译成中文,广告屏蔽插件会导致该功能失效:
问题:
I installed https://github.com/farbelous/bootstrap-colorpicker plugin to my laravel 5.7 / Bootstrap v4.1. / Jquery 3 / Blade application and question is which is the correct way of attaching files I need to my page ? I need this plugin only on some pages, so in this page I did :
...
@endsection
@section('scripts')
...
<script src="{{ asset('js/'.$frontend_template_name.'/print_to_pdf_options.js') }}{{ "?dt=".time() }}"></script>
<link href="../../node_modules/bootstrap-colorpicker/dist/css/bootstrap-colorpicker.css" rel="stylesheet">
<script src="../../node_modules/bootstrap-colorpicker/dist/js/bootstrap-colorpicker.js"></script>
...
<script>
@endsection
But this way does not work and seems invalid. Which way is valid ?
Thanks!
回答1:
You can use Stacks.
From the docs:
Blade allows you to push to named stacks which can be rendered somewhere else in another view or layout. This can be particularly useful for specifying any JavaScript libraries required by your child views:
@push('scripts')
<script src="/example.js"></script>
@endpush
In your Layout:
<head>
<!-- Head Contents -->
@stack('styles')
</head>
<body>
@stack('scripts')
</body>
View where you need the plugin:
@push('styles')
<link href="../../node_modules/bootstrap-colorpicker/dist/css/bootstrap-colorpicker.css" rel="stylesheet">
@endpush
@push('scripts')
<script src="{{ asset('js/'.$frontend_template_name.'/print_to_pdf_options.js') }}{{ "?dt=".time() }}"></script>
<script src="../../node_modules/bootstrap-colorpicker/dist/js/bootstrap-colorpicker.js"></script>
@endpush