4

I have a code of left side category list in left_cat.phtml file. The code is like below.

<div class="block block-left-category">
  <div class="block-title">
        <strong><span><?php echo $this->__('Categories') ?></span></strong>
    </div>
    <div class="block-content">
        <div class="categories-top-list no-dots">
                <a class="category-top" href="#">APPLE</a>
        </div>
        <div class="categories-top-list">
                <a class="category-top" href="#">AUDIO</a>
        </div>
        <div class="categories-top-list">
                <a class="category-top" href="#">AV</a>
        </div>
        <div class="categories-top-list">       
                <a class="category-top" href="#">CAMERAS</a>
        </div>
        <div class="categories-top-list">   
                <a class="category-top" href="#">CCTV</a>
        </div>
        <div class="categories-top-list">
                <a class="category-top" href="#">COMPONENTS</a>
        </div>
        <div class="categories-top-list">       
                <a class="category-top" href="#">MONITORS & TV's</a>
        </div>
        <div class="categories-top-list">   
                <a class="category-top" href="#">NAS Solutions</a>
        </div>
        <div class="categories-top-list">
                <a class="category-top" href="#">PROJECTORS</a>
        </div>
        <div class="categories-top-list">       
                <a class="category-top" href="#">WIRELESS</a>
        </div>
        <div class="categories-top-list">       
                <a class="category-top" href="#">LAPTOPS & NOTEBOOKS</a>
        </div>
        <div class="categories-top-list">       
                <a class="category-top" href="#">NETWORKING</a>
        </div>
        <div class="categories-top-list">       
                <a class="category-top" href="#">PC'S</a>
        </div>
        <div class="categories-top-list">       
                <a class="category-top" href="#">PERIPHERALS</a>
        </div>
        <div class="categories-top-list">       
                <a class="category-top" href="#">PRINTERS & SCANNERS</a>
        </div>
        <div class="categories-top-list">   
                <a class="category-top" href="#">SOFTWARE</a>
        </div>
        <div class="categories-top-list">   
                <a class="category-top" href="#">CLEARANCE</a>
        </div>      
        </div>
    </div>

and in XML file I've put the code like below.

<default>
        <!-- Mage_Catalog -->
        <reference name="left">
            <block type="core/template" name="left.category.list" template="category/left_cat.phtml"/>
        </reference>
</default>

Temporary I put the category list in the PHTML file. But, now I want to add category list in one of the static block and want to fetch that block in the XML file at particular location. I've tried to find solution using many resources, but hard luck.

18

As described on Stackoverflow

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_identifier')->toHtml(); ?> 
8

Below I have the example of add newest products at left side.

<default>
    <reference name="left">
        <block type="cms/block" name="cms_newest_product" as="cms_newest_product" output="toHtml">
            <action method="setBlockId"><block_id>newest_product</block_id></action>
        </block>
    </reference>
</default>
1

Adding a Static Block to your .phtml files in Magento

step 1: Go to Magento admin uder CMS -> Static Blocks and Add New Block. Insert Block Title, Identifier (for example: checkout_logo), set Status to Enabled, insert block Content and Save Block.

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('checkout_logo')->toHtml(); ?>
1

Use this code to call static block in phtml file. For this From Backend CMS -> Static Blocks and create new block. Give identifier to static block and pass identifier in following code.

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_identifier')->toHtml(); ?>
0
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('static block Identifier')->toHtml(); ?>
-2

Its better and safer using {{ }}

For example

Create Block and pass all the data in that block, then call the block as if you are calling a widget.

i.e {{widget type="cms/widget_block" template="cms/widget/static_block/default.phtml" block_id="53"}}

where block_id is the id of the static block you've created

  • pretty sure that won't work in a .phtml – Julien Lachal Jan 27 '15 at 10:39
  • i'v used this many times on some projects – Antivirus_femi Aug 13 '15 at 16:50
  • It would only work in CMS! – Shadowbob Nov 17 '15 at 9:13

protected by Marius Jun 3 '15 at 12:56

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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