gpt4 book ai didi

php - 如何在 Laravel 中添加动态页面标题

转载 作者:行者123 更新时间:2023-12-03 22:54:43 26 4
gpt4 key购买 nike

我想添加一个动态页面标题,就像我有一个帖子列表,当我点击打开的单个帖子详细信息页面时,在这种情况下,我希望该动态标题显示在标题文件中。

@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}} 但它不起作用..它显示类似这样的内容。

This is title); ?> Post Page

在 app.blade.php 上我有这样的东西。

<title>Laravel Practice - @yield('title')</title>

最佳答案

Blade 的变量语法在 @section 调用中无效,因此您需要使用普通的旧 PHP:

@section('title', 'This is ' . $post->title . ' Post Page')

如果 $post->title 是用户输入,您将需要转义内容以免受 XSS 漏洞的影响:

@section('title', 'This is ' . e($post->title) . ' Post Page')

关于php - 如何在 Laravel 中添加动态页面标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45715843/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com