1

Is it possible to return all blocks which contain a specific substring? e.g. return all blocks which contain the substring slider_.

I know I can return all blocks loaded in the current page like this:

$allBlocks = Mage::app()->getLayout()->getAllBlocks();
$blockNames = array_keys($allBlocks);

var_dump($blockNames);

But how can I get ALL blocks, even blocks not loaded at the moment, so I can filter the necessary ones with the target substring out?

Which way is recommended to achieve this?

2
    $blocks = Mage::getModel("cms/block")->getCollection();
    $searchString = 'slider_';
    foreach($blocks as $block) {
        if (strpos($block->getIdentifier(), $searchString) !== false) {
            echo $block->getIdentifier() . '</br>';
        }
    }
| improve this answer | |
  • Works like a charm! – Black Jul 6 '18 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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