【问题标题】:Yii2 how to render radiolist with html content?Yii2如何用html内容呈现radiolist?
【发布时间】:2015-02-02 20:27:21
【问题描述】:

我正在尝试制作一个单选列表,其中包含 html 内容,我想在其中有一个标题和一个图像,来自这段代码:

$items=array();
foreach ($templates['user'] as $template) {
    $item = $template['name'];
    $item .= Html::encode("<div>".Html::img($template['preview_image'])."</div>");
    $items[] = $item;
}

然后显示它

echo Html::radioList('templates', null, $items, ['separator'=>"<hr />",'encode'=>'html']);

但它不起作用。我在视图中获得了 html 代码。有什么想法吗?

提前致谢!

【问题讨论】:

    标签: php html yii2 radiobuttonlist


    【解决方案1】:

    你正在编码你的html就行了:

    $item .= Html::encode("<div>".Html::img($template['preview_image'])."</div>");
    

    尝试删除Html::encode()

    编辑:

    另外,尝试将选项 encode 更改为 false

    echo Html::radioList('templates', null, $items, ['separator'=>"<hr />",'encode'=>false]);
    

    【讨论】:

    • 做到了,但仍然无法正常工作。我看到&lt;label&gt;&lt;input type="radio" name="templates" value="0"&gt;Name of the template&amp;lt;div&amp;gt;&amp;lt;img src="http://localhost/project/image/01.jpg" alt=""&amp;gt;&amp;lt;/div&amp;gt;&lt;/label&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-26
    • 2013-09-08
    • 1970-01-01
    • 2013-11-29
    • 2016-05-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多