简体   繁体   中英

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'

Implemented with Alpine JS

Blade Component (.../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

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

There could be easier methods of doing it the JavaScript way, but this is what I could think of. Hope it helps

The PHP way could be to pass the $title as a prop to the layout, For Example

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

guest-layout.blade.php now looks like

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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