1

as the title might let you suggest I have trouble to get image URL's out of product descriptions in my custom phtml file (located in template folder).

In cms pages/blocks you can use

{{media url="wysywig/Banner/image.jpg"}}

which we do for parts (headlines) of our product descriptions.

Now when I try to display that description out of my phtml file with

<?php echo nl2br($productResult[$i]->getDescription()); ?>

the description gets loaded but the image URL's dont get converted to total URL's like for example "/media/wysywig/banner".

I know that you have to use Mage::getUrl("media") in php/phtml files though this information doesn't help much in my situation.

The only idea I have is to set a string function to search for {{media url="wysywig/banner/image.jpg"}} and replace it with Mage::getUrl("media/wysywig/image.jpg") but I kinda feel like this isn't a very elegant solution.

Or is it the only way? Any help is appreciated. Much thanks and greetings mpfmon

2
  • 2
    Try to filter your description string with this function before the echo: $description = Mage::getSingleton('widget/template_filter')->filter($description);
    – adrien54
    May 29, 2015 at 15:01
  • Yes! Big thanks it worked immediately. This is how I did it: $description = Mage::getSingleton('widget/template_filter')->filter(nl2br($myProduct->getDescription())); echo $description;
    – mpfmon
    May 31, 2015 at 13:58

2 Answers 2

1

It doesn't work because it was not planned for the product description to have such media call:

{{media url="wysywig/Banner/image.jpg"}}

However there is nothing wrong doing this, to make it work, you have to filter your description with a widget function:

echo Mage::getSingleton('widget/template_filter')->filter($description);
0

You must enable "Allow Dynamic Media URLs in Products and Categories" setting in Catalog section of Magento configuration screen. (See attached image)

enter image description here

1
  • This doesn't help when you want to get URLs within custom php files. I did it as adrien54 said. Thanks for the answer anyway.
    – mpfmon
    May 31, 2015 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.