从自定义属性文本框中获取每个值

时间:2015-04-02 14:19:56

标签: magento

我想知道是否有办法将文本框的每行包装成div。

我创建了一个扩展程序,可以在块中获取自定义文本框youtube并将其返回。

例如:

自定义文本框youtube包含(每个iframe一个新行):

<iframe width="560" height="315" src="URL_1" allowfullscreen></iframe>
<iframe width="560" height="315" src="URL_2" allowfullscreen></iframe>

当我获得自定义字段的内容时

return $_product->getYoutube();

我希望它输出:

<div class"youtube"><iframe width="560" height="315" src="URL_1"...</div>
<div class"youtube"><iframe width="560" height="315" src="URL_1"...</div>

希望有人能帮助我。

1 个答案:

答案 0 :(得分:1)

$ _ product-&gt; getYoutube()只返回字符串,因此您只需使用php函数str_replace即可。 尝试类似的东西:

$content = $_product->getYoutube();
//for opening tag
$content = str_replace("<iframe", '<div class="youtube"><iframe', $content);
//for closing tag
$content = str_replace("</iframe>", '</iframe></div>', $content);
return $content;