[我想添加一个动态页面标题,就像我有一个帖子列表,并且当我单击打开的单个帖子详细信息页面时,在这种情况下,我希望该动态标题显示在标题文件中。
@extends('layouts.app')
@section('title', 'This is {{$post->title}} Post Page')
@section('contents')
<h3>{{$post->title}}</h3>
<p>{{$post->body}}</p>
@endsection
您可以在本节中看到。@section('title','这是{{$ post-> title}}帖子页'){{$ post-> title}},但无效。它显示出这样的内容。
这是标题); ?>帖子页
在app.blade.php上,我也有类似的东西。
<title>Laravel Practice - @yield('title')</title>
刀片的变量语法在@section
调用中无效,因此您将要使用普通的旧PHP:
@section('title', 'This is ' . $post->title . ' Post Page')
如果$post->title
是用户输入,您将希望逃避某些事情,以防XSS漏洞:
@section('title', 'This is ' . e($post->title) . ' Post Page')
您不能将{{$ post-> title}}留在''中,只需将其放出并与'。'连接即可。像这样:
@section('title', 'This is' . {{$post->title}} . 'Post Page')