[英]Yii2 how to render radiolist with html content?
I'm trying to make a radio list, with html content inside, where i want to have a title, and an image, from this code: 我正在尝试通过以下代码制作一个单选列表,其中包含html内容,我想在其中包含标题和图像:
$items=array();
foreach ($templates['user'] as $template) {
$item = $template['name'];
$item .= Html::encode("<div>".Html::img($template['preview_image'])."</div>");
$items[] = $item;
}
And then to display it 然后显示它
echo Html::radioList('templates', null, $items, ['separator'=>"<hr />",'encode'=>'html']);
But it doesn't work. 但这是行不通的。 I get the html code in the view. 我在视图中获得了html代码。 Any ideas? 有任何想法吗?
Thanks in advance! 提前致谢!
You are encoding your html on the line: 您正在对HTML进行编码:
$item .= Html::encode("<div>".Html::img($template['preview_image'])."</div>");
Try removing Html::encode()
. 尝试删除Html::encode()
。
Edit: 编辑:
Also, try changing the option encode
to false
: 另外,尝试将options encode
更改为false
:
echo Html::radioList('templates', null, $items, ['separator'=>"<hr />",'encode'=>false]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.