Laravel刀片-如果满足条件则添加一个类 [英] Laravel blade - Add a class if a condition is met

查看:63
本文介绍了Laravel刀片-如果满足条件则添加一个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很简单,但是我似乎无法使用Blade做到这一点,我通常会为此返回到php,但是,因为我无法使用Blade声明新的php变量(不打印它,那就是)如果满足特定条件,应如何更改简单的类名?以链接的此示例为例,如果$ hostess-> active = 1

This is simple but I can't seem to be able to do it with blade and I usually go back to php for this but, since I can't declare a new php variable with blade (without printing it, that is) how should I change a simple class name if a certain condition is met? Take this example of a link, I just want to add the class "active" if $hostess->active=1

 {{ HTML::linkRoute('hostesses.index', 'Archived', $params, array('class' => 'btn btn-default')) }}

我知道如何使用php来做到这一点,但是如何使用Blade来完成呢?

I know how to do this with php, but how would it be done with blade?

推荐答案

像这样吗?

{{ HTML::linkRoute('hostesses.index', 'Archived', $params, array('class' => $hostess->active ? 'btn btn-info' : 'btn btn-default')) }}

这篇关于Laravel刀片-如果满足条件则添加一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆