How to attach bootstrap-colorpicker to my laravel/blade page?

问题: 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
  • 发表于 2018-12-25 15:46
  • 阅读 ( 271 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除