RoRo
RoRo

Reputation: 15

Get every value from a custom attribute textbox

I am wondering if there is any way to wrap every line of a textbox into a div.

I created a extension that gets the custom textbox youtube in a block and returns it.

For example:

The custom textbox youtube contains (every iframe one a new line):

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

when i get the content of the custom field

return $_product->getYoutube();

i want it to output:

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

Hope somebody can help me with this.

Upvotes: 0

Views: 331

Answers (1)

user1992836
user1992836

Reputation:

$_product->getYoutube() just returns string, so you can just use php function str_replace. Try something like that:

$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;

Upvotes: 1

Related Questions