问题
I'm displaying you-tube video on front end of the website. Admin can provide the you-tube source from embedded code from Site back end. I want to have a preview on view page. Following is the code I tried but it is displaying the iframe tags as it is (I know this is not the right way)
[
'attribute'=>'source',
'value' => !empty($model->source) ? '<iframe class="embed-responsive-item" src="'.$model->source.'" frameborder="0" allowfullscreen></iframe>' : NULL,
],
is there any thing like it has for image format:
[
'label'=>'Image',
'attribute'=>'userInfo.image',
'format' => ['image',['width'=>'100','height'=>'100']],
],
回答1:
Format html
or raw
will help you.
[
'format' => 'raw',
'attribute'=>'source',
'value' => !empty($model->source) ? '<iframe class="embed-responsive-item" src="'.$model->source.'" frameborder="0" allowfullscreen></iframe>' : null,
],
来源:https://stackoverflow.com/questions/32859125/how-to-render-youtube-video-in-yii2-detailview-widget