@yield和@include之间的区别在于Laravel刀片模板导入CSS



刀片中这两个关键词的主要区别是什么,我发现它们做的是一样的,但。。。语法不同,但主要区别是什么?我正在使用@yield和@include,但不知道用哪个更好?

我想扩展我的CSS样式,我想在需要时加载CSS样式,例如,我想将样式和选项分离到nawbar,并将CSS样式分离到我在nawbar.CSS中定义的页脚,footer.CSS,我想包括在我的main.blade.php中,但页脚不是始终可见的?

如何解决这个问题?我想错了吗,最好把所有css放在一个文件里?性能如何?

    <!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="expires" content="-1" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title> Authentication system</title>
    {{--custom css--}}
    @yield('css')
    {{HTML::style('css/bootstrap.min.css')}}
    <!-- Custom styles for this template -->
    {{HTML::style('css/navbar.css')}}
</head>
<body>
@if(Session::has('global'))
    <p>{{Session::get('global')}}</p>
@endif
@include('layout.navigation')
@yield('content')
@yield('layout.footer')

和页脚

@extends('layout.main')
@section('css')
    @parent
    {{HTML::style('css/footer.css')}}
@endsection
@section('footer')
    <footer class="footer">
        <div class="container">
            <div class="row">
                <div class="col-md-4">
                </div>
                <div class="col-md-4"></div>
                <div class="col-md-4"></div>
                <
            </div>
        </div>
    </footer>
@endsection

我的代码不起作用。

而不是

@yield('layout.footer')

写入

@include('layout.footer')

这应该能解决你的问题。

最新更新