0

I want get path of image of cms-block and here is code:

$yourPageIdentifier   = 'home_banner';
$cmsPage              = Mage::getModel('cms/block')->setStoreId($store_id)->load($yourPageIdentifier,'identifier');
$array['title']       = $cmsPage->getTitle();
$array['identifier']  = $cmsPage->getIdentifier();
$array['content']     = htmlentities($cmsPage->getContent());

Help me get this.

2
  • you want to get all images from cms content ?
    – Arunendra
    Commented Aug 2, 2017 at 9:30
  • yah! you are right.. Commented Aug 2, 2017 at 9:36

1 Answer 1

0

Try this code:

<?php
    $helper = Mage::helper('cms');
    $processor = $helper->getPageTemplateProcessor(); 
    $html = $processor->filter($array['content']);
    $doc = new DOMDocument();
    @$doc->loadHTML($html);

    $tags = $doc->getElementsByTagName('img');

    foreach ($tags as $tag) {
           echo $tag->getAttribute('src');
    }
    ?>
3
  • working fine but i get "image": [ "{{media url=", "{{media url=", "{{media url=" ] Commented Aug 2, 2017 at 9:50
  • after media url there is no image path Commented Aug 2, 2017 at 9:52
  • I have updated the answer plz check
    – Arunendra
    Commented Aug 2, 2017 at 9:54

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.