2016-12-03 22 views
1

のファイルにyieldを入れようとしていますが、動作しません。Laravelブレードにコンテンツが表示されない

これは私のindex.blade.phpです:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html lang="en"> 
<head> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <meta name="token" content="{{ csrf_token() }}"> 
    <title>Forum</title> 
    <link href="https://fonts.googleapis.com/css?family=Lato:100,200,300,400" rel="stylesheet" type="text/css"> 
    <link href='https://fonts.googleapis.com/css?family=Roboto:400,500,700' rel='stylesheet' type='text/css'> 
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> 

    <link href="/css/bulma.css" rel='stylesheet' type='text/css'> 
    <link href="/css/all.css" rel='stylesheet' type='text/css'> 
</head> 
<body> 
<div id="app"> 
    @include('shared.menu.menu') 
    @yield('content') 
</div> 
<script src="/js/app.js"></script> 
</body> 
</html> 

これは私のlogin.blade.phpです:

@extends('index') 
    @section('content') 
     @yield('shared.bar.bar') 
    @stop 

だから、ナビゲーションバーには、この時点で表示されます。しかし、バーはありません!私が交換:@yield('shared.bar.bar')testtestが表示されます。これはshared/bar/bar.blade.php

@section('bar') 
<section class="hero is-primary"> 
    <div class="hero-body"> 
     <div class="container"> 
      <h1 class="title"> 
       test 
      </h1> 
      <h2 class="subtitle"> 
       test 
      </h2> 
     </div> 
    </div> 
</section> 
@stop 

私は間違っていますか?変数をバーに渡すことも可能ですか?だから私はすべてのページに別のtitlesubtitleを表示できますか?

--EDIT--

@section('bar') 
<section class="hero is-primary"> 
    <div class="hero-body"> 
     <div class="container"> 
      <h1 class="title"> 
       {{ $title }} 
      </h1> 
      <h2 class="subtitle"> 
       {{ $subtitle }} 
      </h2> 
     </div> 
    </div> 
</section> 
@stop 

答えて

1

あなたはあなたのコードのすべてを見せている場合は、あなたの収量は

@yield('shared.bar.bar') 

そして、youtはセクション

@section('bar') 

それが必要であるように見えますbe

@section('shared.bar.bar') 

それとも@yield@sectionは文字列だけなので、あなたは

@yield('bar') 

にあなたの歩留まりを変更する必要があり、彼らは@includeのようなファイルに関連するものではありません。

そして、このファイルも間違っているように見えます:

@extends('index') 

@section('content') 
    @yield('shared.bar.bar') 
@stop 

@yieldは、それが起こっているundestandするために汚いとハードと難しい得ることができますので、あなたが、あなたのメインのレイアウトファイルでのみ使用を開始すべきものです。だから、セクション 'shared.barを持っていない限り。この@yieldを埋めるバー」は、おそらくタイトルを持っている

@extends('index') 

@section('content') 
    <form> 
     .... your login form 
    </form> 
@stop 

または

@extends('index') 

@section('content') 
    @include('shared.bar.bar') 
@stop 

または

@extends('index') 

@section('content') 
    @include('shared.bar.bar') 

    <form> 
     .... your login form 
    </form> 
@stop 

のようなものはあなたにも行うことができます部を介して変更されないはずです。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html lang="en"> 
<head> 
    <title>@yield('title')</title> 
</head> 

または

<h1 class="title"> 
    @yield('title') 
</h1> 

、ログインブレードファイル、私は両方の `それはまだ働いていないbar```` `それらを呼び出す

@extends('index') 

// This will tell the Blade Compiler to replace every 
// occurence of @yield('title') 
@section('title') 
    User Login 
@stop 

@section('content') 
    @include('shared.bar.bar') 

    <form> 
     .... your login form 
    </form> 
@stop 
+0

こんにちは、行うことができます。また、私はそれらを '' '' shared.bar.bar'''と呼びます。 – Jamie

+0

あなたがそれらを間違って設計したように見えます。私の編集を見てください。 –

+0

私を助けてくれてありがとう。また、2つのパラメータを渡したいと思います(上記の私の編集を参照)。しかし、それは ''インクルード ''では不可能です。だから私は ''利回り ''を使うのです。 – Jamie

関連する問題