Dynamic navbar Laravel page name

I have layouts.app.blade.php where I have <html> and <body> tags, as well as <nav> tags.
In <body> I give content for each page, so they basically extend this .blade.php application.
All the main Laravel stuff, so now I have this:

  <div class="navbar-header"> <!-- Collapsed Hamburger --> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#spark-navbar-collapse"> <span class="sr-only">Toggle Navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <!-- Branding Image --> <a class="navbar-brand" href="/"> *Dynamic page title* </a> </div> // ... @yield('content') 

And I would like to use this <a class="navbar-brand"> to display my list. Thus, this means that it must change for each downloadable template (using @yield ('content')) in this "parent.blade.php".

How do I do this using Laravel 5.2?

Many thanks

+9
jquery php dynamic twitter-bootstrap laravel
source share
4 answers

If this is your main page title below

 <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> 

then the name of your page can be changed on the page of your blade, as shown below

 @extends('layouts.master') @section('title', 'Page Title') @section('sidebar') @parent <p>This is appended to the master sidebar.</p> @endsection @section('content') <p>This is my body content.</p> @endsection 

More information can be found here. Laravel Docs

+23
source share

You can pass it by type, for example

controller

 $title = 'Welcome'; return view('welcome', compact('title')); 

View

 isset($title) ? $title : 'title'; 

or php7

 $title ?? 'title'; 

Null Coalescence Operator

0
source share

The blade looks like this-

 return view('front.list',compact('artists','letter')); 

instead of-

 return view('front.list',compact('artists')); 

And now, in your opinion, you can use:

 <title>Artists begging with {{ $letter }}</title> 
0
source share

Complementing the above decision about using a variable in your view, if you extend the layout (you must do this), you can display it like this if you have a section title: @section ("title", "$ letter"). Thanks to the power of the blade. Hope this is helpful.

0
source share

All Articles