【问题标题】:How can I add an if condition to a html::img helper?如何将 if 条件添加到 html::img 助手?
【发布时间】:2018-01-18 12:20:53
【问题描述】:

如何将if 条件添加到html::img 助手?如何通过if 条件向 Yii2 图像添加类?

【问题讨论】:

标签: php yii2 frameworks


【解决方案1】:

使用三元运算符:

<?= Html::img(
       'Image Location',
       [
          'class' => (condition) ? 'class-true' : 'class-false',
          'alt' => 'Image',
       ]
) ?>

【讨论】:

    猜你喜欢
    • 2022-12-18
    • 2020-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-06
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    相关资源
    最近更新 更多