dongliping003116 2014-06-22 09:00
浏览 9
已采纳

laravel如何根据消息设置类

I have a dropdown and I have styled it in a way that the current opened li is colored red.

This dropdown menu locates at the left of the page. and this menu exist in all pages.

All pages just set the content of other div in the page but the menu is always for all of them (I hope you get me).

In the controller I do this:

return View::make('restaurants.admins')->with('admin', $admin)->with('verticalMenu' , 'Admin');

So in the view I want to check this verticalMenu value, if it is admin, I will set admin's li class to open class and so on.

I will show you an example of what I want.

this is li that is closed

<li class="dropdown">
    <a href="javascript:;">
        <i class="fa fa-user"></i> Restaurant <span class="caret"></span>
    </a>
    <!-- more html here -->
</li>

This is li that is opened because it has the class open

<li class="dropdown active opened">
    <a href="javascript:;">
        <i class="fa fa-tasks"></i> Profile <span class="caret"></span>
    </a>
    <!-- more html here -->
</li>

So basically, I need to check the {{$verticalMenu}} before each li, right?, if yes, how please? if no, what is the correct way please?

After your answer

This is the mistake page, please look how the profile li is opened:

![Screen shot of the actual page][1]

This is the good one, where everything is perfect:

  • 写回答

1条回答 默认 最新

  • dsff788655567 2014-06-22 09:09
    关注

    The {{ }} basically turns a code like this:

    {{ $verticalMenu }} 
    

    Into this:

    <?php echo $verticalMenu; ?>
    

    What you are trying to achieve is this:

    <?php echo $verticalMenu == 'Admin' ? 'active opened' : '' ?>
    

    So the most straight-forward way to do it with blade syntax is:

    <li class="dropdown {{ $vericalMenu == 'Admin' ? 'active opened' : '' }}">
        <!-- The rest of the list content here -->
    </li>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度