Reputation: 562
I want to add a dynamic page title like I have a post list and when I click on a single post details page open, in that case, I want that dynamic title to be displayed in head title file.
@extends('layouts.app')
@section('title', 'This is {{$post->title}} Post Page')
@section('contents')
<h3>{{$post->title}}</h3>
<p>{{$post->body}}</p>
@endsection
You can see in this section. @section('title', 'This is {{$post->title}} Post Page') {{$post->title}} but its not working.. its showing something like this.
This is title); ?> Post Page
And on app.blade.php I have something like this.
<title>Laravel Practice - @yield('title')</title>
Upvotes: 3
Views: 6298
Reputation: 180004
Blade's variable syntax isn't valid in a @section
call, so you'll want to use plain old PHP:
@section('title', 'This is ' . $post->title . ' Post Page')
If $post->title
is user input, you're going to want to escape things to be safe from XSS vulnerabilities:
@section('title', 'This is ' . e($post->title) . ' Post Page')
Upvotes: 10
Reputation: 512
You can't leave {{$post->title}} inside '', just put it out and connect with '.' like this :
@section('title', 'This is' . {{$post->title}} . 'Post Page')
Upvotes: -1