Laravel 7 从包含的布局或组件中提取 css / js
Laravel 7 extract css / js from included layout or component
我正在尝试使用 Laravel 7 构建网站,但我一直在从部分布局提取 JS 或 CSS 到主布局。我的 app.blade.php
布局应该由滑块等较小的部分构建。我的主要问题是我无法将特定 CSS 附加到 <head>
或将滑块 js
附加到页面底部。它适用于 @extends()
,但在这种情况下,我想使用 @inclide
或 <x-component/>
。滑块更静态但想在某些地方重用此代码。我也尝试了 @push
和 @stack
但在布局不扩展 app.layout
之前仍然无法做到
<head>
@yield('css')
</head>
<body>
<x-test></x-test>
@include('layouts.navbar')
@include('layouts.slider') <-slider js
@yield('content')
@yield('js')
</body>
</html>
看来我指向了错误的布局。如果我使用子布局中的@stack/@pull 或@yield/@section(这个带有@extend('layout.app'))那么所有的工作fine.Also,它呈现顶部和底部部分。
示例:
app.blade.php
<head>
@yield('css')
</head>
<body>
@yield('content')
</body>
index.blade.php
@extends('layouts.app')
@include('layouts.test')
test.blade.php
@push('xxx2')
text
@endpush
@section('css')
css
@endsection
我正在尝试使用 Laravel 7 构建网站,但我一直在从部分布局提取 JS 或 CSS 到主布局。我的 app.blade.php
布局应该由滑块等较小的部分构建。我的主要问题是我无法将特定 CSS 附加到 <head>
或将滑块 js
附加到页面底部。它适用于 @extends()
,但在这种情况下,我想使用 @inclide
或 <x-component/>
。滑块更静态但想在某些地方重用此代码。我也尝试了 @push
和 @stack
但在布局不扩展 app.layout
<head>
@yield('css')
</head>
<body>
<x-test></x-test>
@include('layouts.navbar')
@include('layouts.slider') <-slider js
@yield('content')
@yield('js')
</body>
</html>
看来我指向了错误的布局。如果我使用子布局中的@stack/@pull 或@yield/@section(这个带有@extend('layout.app'))那么所有的工作fine.Also,它呈现顶部和底部部分。
示例:
app.blade.php
<head>
@yield('css')
</head>
<body>
@yield('content')
</body>
index.blade.php
@extends('layouts.app')
@include('layouts.test')
test.blade.php
@push('xxx2')
text
@endpush
@section('css')
css
@endsection