Laravel blade 未显示内容
Laravel blade not showing content
我正在尝试 yield
我的 blade
文件之一,但它不起作用。
这是我的 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
如果您展示了所有代码,那么您的收益似乎是
@yield('shared.bar.bar')
还有你的部分
@section('bar')
什么时候应该
@section('shared.bar.bar')
或者您应该将收益更改为
@yield('bar')
因为@yield
和@section
只是字符串,与@include
.
等文件无关
看起来这个文件也是错误的:
@extends('index')
@section('content')
@yield('shared.bar.bar')
@stop
@yield 是你应该只在你的主布局文件中开始使用的东西,因为它会变得混乱和难以理解正在发生的事情。所以,除非你有一个 'shared.bar.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>
还有你的登录blade文件,就可以了
@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
我正在尝试 yield
我的 blade
文件之一,但它不起作用。
这是我的 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
如果您展示了所有代码,那么您的收益似乎是
@yield('shared.bar.bar')
还有你的部分
@section('bar')
什么时候应该
@section('shared.bar.bar')
或者您应该将收益更改为
@yield('bar')
因为@yield
和@section
只是字符串,与@include
.
看起来这个文件也是错误的:
@extends('index')
@section('content')
@yield('shared.bar.bar')
@stop
@yield 是你应该只在你的主布局文件中开始使用的东西,因为它会变得混乱和难以理解正在发生的事情。所以,除非你有一个 'shared.bar.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>
还有你的登录blade文件,就可以了
@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