【问题标题】:Difference between @yield and @include Laravel Blade Templating importing CSS@yield 和 @include Laravel Blade 模板导入 CSS 的区别
【发布时间】:2015-06-08 11:00:02
【问题描述】:

blade中这两个关键字的主要区别是什么,我发现它们做同样的事情,但是...语法不同,但主要区别是什么? 我正在使用@yield 和@include,但没有弄清楚哪个更好用?

我想扩展我的 CSS 样式,我想在需要时加载 css 样式,例如,我想将样式和选项分开到导航栏,并将 css 样式分开到我在 navbar.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

我的代码不起作用。

【问题讨论】:

  • 也许,但我编辑了更具体的信息。
  • 如果你想要具体的答案,你需要包含一些代码。
  • 我在导航栏中使用了 include,但我在 main.blade.php 中加载了 CSS。但我想在 footer.blade.php 中加载 CSS 作为现有 CSS 的扩展。

标签: css laravel blade


【解决方案1】:

代替

@yield('layout.footer')

@include('layout.footer')

这应该可以解决您的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-18
    • 2016-02-27
    • 2021-09-18
    • 2018-11-07
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    相关资源
    最近更新 更多