首页 > 解决方案 > Laravel:如何在选定视图中包含外部链接

问题描述

我已经在<header>我的索引视图的标签下包含了所有的 css 和 js 外部链接。

现在有一些我想要的外部链接load on selected views only

我可以在该视图上单独添加链接,但是that link will go out of <head> tag

如何仅从<header> tag of index view.

我试过了

<head>
...other links
     @if(View::exists('ispblade.calendar'))
            @include('ispblade.calendar_links')
        @endif 
</head>

但它正在加载选定的链接all views

标签: laravellaravel-8

解决方案


你需要使用stacks它。

在布局中:

<head>
    <!-- Head Contents -->

    @stack('scripts')
</head>

在您看来:

@push('scripts')
    <script src="/example.js"></script>
@endpush

https://laravel.com/docs/8.x/blade#stacks


推荐阅读