How to render youtube video in YII2 DetailView widget

百般思念 提交于 2019-12-12 17:16:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!