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')
與test
,test
顯示出來。這是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
我在做什麼錯?是否也可以將變量傳遞給酒吧?所以我可以在每個頁面上顯示另一個title
和subtitle
?
- 編輯 -
@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
嗨,我都稱之爲'''bar'''它仍然沒有工作。另外當我把它們都叫做'''shared.bar.bar'''。 – Jamie
看起來你錯誤地構建了它們,看看我的編輯。 –
感謝您的幫助。我也想傳遞2個參數(參見上面的我的編輯)。但是'''include'''不可能。這就是我使用yield的原因。 – Jamie