简体   繁体   English

使用整页组件时如何更改页面标题-Livewire

[英]How can I change page title when I use full page components-Livewire

<head>
   <title>dynamic title here - {{ config('app.name') }}</title>
</head>

if you try this, please let me know.如果你试试这个,请告诉我。

I preferred using JavaScript with Blade Components document.title = 'My Title'我更喜欢使用 JavaScript 和 Blade Components document.title = 'My Title'

Implemented with Alpine JSAlpine JS实现

Blade Component (.../components/page-title.blade.php)刀片组件 (.../components/page-title.blade.php)

@props(['title'])

<div x-data x-init="document.title = @js($title.' - '.config('app.name'))"></div>

so you can call the page-title component anywhere in your blade flies like this所以你可以像这样在你的刀片中的任何地方调用page-title组件

<x-page-title :title="'Homepage'" />

There could be easier methods of doing it the JavaScript way, but this is what I could think of.可能有更简单的方法可以用 JavaScript 的方式来做,但这是我能想到的。 Hope it helps希望能帮助到你

The PHP way could be to pass the $title as a prop to the layout, For Example PHP 的方式可能是将$title作为道具传递给布局,例如

<x-guest-layout :page-title="$title">
... Page Content
</x-guest-layout>

guest-layout.blade.php now looks like guest-layout.blade.php现在看起来像

@props(['title'])
<html>
  <head>
      <title>{{ $title }}</title>
  </head>
  <body>
    {{ $slot }}
  </body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM