laravel-livewire - 使用整页组件时如何更改页面标题-Livewire
问题描述
<head>
<title>dynamic title here - {{ config('app.name') }}</title>
</head>
如果你试试这个,请告诉我。
解决方案
我更喜欢将 JavaScript 与 Blade 组件一起使用document.title = 'My Title'
刀片组件 (.../components/page-title.blade.php)
@props(['title'])
<div x-data x-init="document.title = @js($title.' - '.config('app.name'))"></div>
page-title
所以你可以像这样在你的刀片苍蝇中的任何地方调用组件
<x-page-title :title="'Homepage'" />
可能有更简单的方法可以通过 JavaScript 方式进行,但这是我能想到的。希望能帮助到你
PHP的方式可能是将$title
作为道具传递给布局,例如
<x-guest-layout>
<x-slot name="title">
Custom Title
</x-slot>
...Page Content
</x-guest-layout>
guest-layout.blade.php
现在看起来像
<html>
<head>
<title>{{ $title ?? 'Todo Manager' }}</title>
</head>
<body>
<h1>Todos</h1>
<hr/>
{{ $slot }}
</body>
推荐阅读
- c# - 错误 System.Runtime.InteropServices.COMException:'对不起,我们找不到 xxx.xlsx。有没有可能它被移动、重命名或删除?
- twilio - Client.getConversationByUniqueName 和 Client.getConversationBySid 找不到其他用户创建的对话
- asp.net - 如何使用 Serilog 注册 Microsoft Logger
- node.js - NestJS/Mongoose - 在钩子里面查询
- flutter - Flutter:agora rtc 引擎使应用程序在另一台设备上崩溃
- linux - 如何在 bash 中创建一个“停止”脚本来关闭我之前使用不同的 bash 脚本打开的 gnome-terminal 选项卡?
- angular - Angular DI 注入令牌的类型与工厂的返回值类型不匹配,但服务接受
- makefile - GNU make 中 for 循环中的字符串替换
- reactjs - React Native 固定页脚不会停留在滚动上
- javafx - GLUON Mobile 找不到基本名称 com.gluonapplication.views.primary 的捆绑包