Magento - How do you return results of unlimited CMS Static blocks (with certain “Identifier”) to a CMS Page

前端 未结 1 1729
清酒与你
清酒与你 2021-01-11 17:24

Quick Overview: I am trying to return results from a specific set of static blocks to a phtml file (which is then called on from a

相关标签:
1条回答
  • 2021-01-11 17:48

    You are not printing block inside foreach loop. Solution: move } parenthesis to the end of pasted code

    $blockNum = 1;
    foreach($collection as $key => $value){
        $_blockId = $this->getIdentifier();
        $block_ID = $_blockId . $blockNum;
        echo "Key: " . $key . " - " . "Block ID: " . $block_ID . "<br />";
        $blockNum++;    
    
        $_block = $this->getLayout()->createBlock('cms/block')->setBlockId($block_ID);
    
        if ($_block) : ?>
            <div class="block block-testimonial">
                <div class="block-title">
                    <strong><?php echo $this->getTitle(); ?></strong>
                </div>
            <div class="block-content">
            <?php echo $_block->toHtml(); ?>
            </div>
        <?php 
        endif;
    }
    

    I think that on Magento Connect are some Testimonial Modules, that are doing job you want. On the other hand, if you are looking for 'simple' solution or if you are trying to play with Magento, is this approach ok.

    0 讨论(0)
提交回复
热议问题