I'm creating a laravel application using bootstrap 4.
I have my main navigation menu in app.blade.php
. And I have four main blades, About,Product,Contact and Blog.
Then I needed to change the menu item active class according to the current page. As the menu being loaded dynamically from the app.blade.php
I had to set the active class for current page in the navigation menu dynamically.
What I did was in every blade I've defined a variable called, $currentpage
and assign page name in to it, assume it's blog.blade.php
<?php $currentPage = 'blog';?>
@extends('layouts.app')
@section('content')
and in the app.blade.php
,
<li class="<?php if($currentPage =='blog'){echo 'nav-item active';}?>">
<a class="nav-link " href=""></a>
</li>
So this works properly..
but I want to know Is this the correct way of doing it and what are the other possible ways to fulfill my requirement
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Y93iXB
via IFTTT
Aucun commentaire:
Enregistrer un commentaire