Laravel 4.1 Request::is for active menu not working

Deadly 提交于 2019-12-04 05:43:23

In Laravel 4.2:

By name:

<li class="{{ Route::is('user') ? 'active' : ''}}">Profile</li>

router.php

Route::get('/user/{id}', ['as' => 'user', 'uses' => 'UserController@profile']);

By url:

<li class="{{ Request::is('user/*') ? 'active' : '' }}">Profile</li>
Moe

changed to:

<li
   {{{ (Request::is('/core') ? 'class=active' : '') }}}><a href="{{{ URL::to('/core')  }}}">Control Panel</a>
</li>

from 'class="active"' to 'class=active'

This working fine for <li> tag but not <a> tag, needs to be used like so:

<a href="{{{ URL::to('core') }}}" class="list-group-item {{{ (Request::is('core') ? 'active' : '') }}}">Overview</a>

you can do like Ahmed Siouani said and use Request if you use a true url or if you use a route you can do something like this :

class="{{ URL::route('my.route') === URL::current() ? 'active' : '' }}"

You're using the triple brace {{{ }}} syntax, which is causing any output to be auto-escaped into HTML entities. That's messing with your output (HTML attributes aren't supposed to be escaped).

Use the triple braces when outputting data that is user-generated, or other instances where you do not control it and can't rely on it being 100% secure. If you're displaying URLs, classes, and other items that you are generating yourself, use the standard echo syntax {{ }}

Update for Laravel 5: The raw, unescaped Blade syntax is now {!! !!}. By default, Laravel 5 will escape both the original double and triple brace structures.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!