简体   繁体   中英

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:

$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. Any ideas?

Thanks in advance!

You are encoding your html on the line:

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

Try removing Html::encode() .

Edit:

Also, try changing the option encode to false :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM