2015-04-03 132 views
3

这两个关键字在刀片服务器上的主要区别是什么,我发现它们做的是同样的事情,但是......语法不同,但最主要的区别是什么? 我正在使用@yield和@include,但没有弄清楚,哪个更好用?我想在需要时加载css样式,例如我想将样式和选项分隔到导航栏中,并将单独的css样式分隔到在navbar.css,footer.css,i中定义的页脚中想要包含在我的main.blade.php中,但是页脚并不总是可见的?@yield和@include之间的差异Laravel Blade模板导入CSS

如何解决这个问题?我认为是错的,最好把所有的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 

我的代码不能正常工作。

+1

可能重复的[Laravel-区别@yield和@section?](http://stackoverflow.com/questions/29070456/laravel-difference-between-yield-and-section) – 2015-04-03 10:54:02

+0

也许,但我编辑为更具体的信息。 – pvaitonis 2015-04-03 11:08:11

+0

如果你想要特定的答案,你需要包含一些代码。 – Bogdan 2015-04-03 11:15:20

回答

0

而不是

@yield('layout.footer') 

@include('layout.footer') 

这应该解决您的问题。