[英]How can I add dynamic page title in Laravel
I want to add a dynamic page title like I have a post list and when I click on a single post details page open, in that case, I want that dynamic title to be displayed in head title file. 我想添加一个动态页面标题,就像我有一个帖子列表一样,当我单击打开的单个帖子详细信息页面时,在这种情况下,我希望该动态标题显示在标题文件中。
@extends('layouts.app')
@section('title', 'This is {{$post->title}} Post Page')
@section('contents')
<h3>{{$post->title}}</h3>
<p>{{$post->body}}</p>
@endsection
You can see in this section. 您可以在本节中看到。 @section('title', 'This is {{$post->title}} Post Page') {{$post->title}} but its not working.. its showing something like this.
@section('title','This is {{$ post-> title}} Post Page'){{$ post-> title}},但无法正常工作。显示类似这样的内容。
This is title);
这是标题); ?> Post Page
?>帖子页
And on app.blade.php I have something like this. 在app.blade.php上,我有类似的内容。
<title>Laravel Practice - @yield('title')</title>
Blade's variable syntax isn't valid in a @section
call, so you'll want to use plain old PHP: Blade的变量语法在
@section
调用中无效,因此您将要使用普通的旧PHP:
@section('title', 'This is ' . $post->title . ' Post Page')
If $post->title
is user input, you're going to want to escape things to be safe from XSS vulnerabilities: 如果
$post->title
是用户输入,那么您将想逃避XSS漏洞的危害:
@section('title', 'This is ' . e($post->title) . ' Post Page')
You can't leave {{$post->title}} inside '', just put it out and connect with '.' 您不能将{{$ post-> title}}留在''之内,只需将其放入并与'。'相连即可。 like this :
像这样 :
@section('title', 'This is' . {{$post->title}} . 'Post Page')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.