As Laravel use Blade template engine, many time we have to use the page title to be displayed dynamically,
Let's Consider you have a master layout for your app.
which have a structure something like
<html>
<head>
<title>App Name - @yield('title')</title>
</head>
<body>
@section('sidebar')
This is the master sidebar.
@show
<div class="container">
@yield('content')
</div>
</body>
Here in Master Layout the code for title is.
<title>App Name - @yield('title')</title>
Then You load the Content Page which looks like.
@extends('layouts.master')
@section('title') {{'Page Title Goes Here'}} @endsection
@section('content')
<p>This is my body content.</p>
@endsection
Here in Content file the code for title is.
@section('title') {{'Page Title Goes Here'}} @endsection
You can watch the video below for live coding.
Thank You for Reading
Reach Out To me.
Twitter
Instagram
TechToolIndia
Top comments (5)
What about a component?
Do I have to use
@props
to pass the title manually to the parent component from a child component?hi
If you are using Vue Components then you can use
props
to pass data from parents to child.I'm using Laravel Blade's Component utilizing the
php artisan make:component
commandhello, I work on a web system and the index pages work correctly, but when I have to put ex:
@section('title')
@endsection
it just breaks ... I've attached images so you can get a sense of what's going on, please help me
dev-to-uploads.s3.amazonaws.com/up...
dev-to-uploads.s3.amazonaws.com/up...
sry for my bad english, I'm using google translate
Hi @omatheusoliveira
.You can't put HTML in title as It goes inside
Hope It's Clear now.