Laravel Blade 模板
Laravel Blade Template
我有一个 blade 模板,我扩展并传递了一个页面标题。我存储在我的数据库中的页面标题。
将页面标题变量传递给布局时,我得到以下信息:
name); ?>
我应该什么时候得到
Art
查看我的 blade 模板
<h1>@yield('title')</h1>
查看我的扩展 blade 布局
@extends('templates.front')
@section('title', '{{ $category->name }}')
有人能看出我做错了什么吗?
您在传递变量时不使用 Laravel blade 语法。
@section('title', $category->name)
请记住,{{}}
中的任何内容或作为 @func()
变量传递的内容均由 PHP 按字面解释。
当您调用 Blade 视图时,您必须使用控制器功能或路由
在该函数中以某种方式获取您的页面标题然后传递给您的视图
例如:
public function index()
{
$title = DB::table('')->where()->get();
return view('home',compact('title'));
}
那么在你看来你可以使用
{{$title}}
定义一个Blade布局
<title>App Name - @yield('title')</title>
使用 Blade 布局
@extends('layouts.master')
@section('title', 'Page Title')
//根据您的要求,页面标题是字符串,因此在 '' 中,
但是如果你使用变量那么你可以直接写变量名
@section('title', $category->name)
我有一个 blade 模板,我扩展并传递了一个页面标题。我存储在我的数据库中的页面标题。
将页面标题变量传递给布局时,我得到以下信息:
name); ?>
我应该什么时候得到
Art
查看我的 blade 模板
<h1>@yield('title')</h1>
查看我的扩展 blade 布局
@extends('templates.front')
@section('title', '{{ $category->name }}')
有人能看出我做错了什么吗?
您在传递变量时不使用 Laravel blade 语法。
@section('title', $category->name)
请记住,{{}}
中的任何内容或作为 @func()
变量传递的内容均由 PHP 按字面解释。
当您调用 Blade 视图时,您必须使用控制器功能或路由 在该函数中以某种方式获取您的页面标题然后传递给您的视图 例如:
public function index()
{
$title = DB::table('')->where()->get();
return view('home',compact('title'));
}
那么在你看来你可以使用
{{$title}}
定义一个Blade布局
<title>App Name - @yield('title')</title>
使用 Blade 布局
@extends('layouts.master')
@section('title', 'Page Title')
//根据您的要求,页面标题是字符串,因此在 '' 中, 但是如果你使用变量那么你可以直接写变量名
@section('title', $category->name)