我在 php 中有这个:
'position' => [
'label' => ['Pic Position', ''],
'inputType' => 'select',
#'default' => 'left',
'options' => [
'left' => 'Left',
'right' => 'Right',
],
]
现在我想要如果选择了“左”,那么一个名为左的类被添加到一个 div 中!我无法弄清楚 php 语法!
<div class="floating_text" <?php if ($this->position == 'left') echo 'class="left"' ?>>
<?= $this->text ?>
</div>
这显然是错误的!
将您的 PHP 条件移至现有条件,class=
而不是尝试创建另一个class=
错误的实例。
<div class="floating_text <?php echo ($this->position == 'left') ? 'left' : '' ?>">
<?= $this->text ?>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句