Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How can I get the contents of a static block? 
 
Sintax
Member
 
Total Posts:  58
Joined:  2008-02-18
Hungary
 

What is the Magento way of getting the “contents” of a CMS Static Block? I want the actual HTML code which can be inserted into a page’s div.

I was thinking of querying the cms_block table’s content and using that, however there must be a Magento way to do this?

::Sintax

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

Are you trying to embed CMS block’s HTML into external PHP script?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Sintax
Member
 
Total Posts:  58
Joined:  2008-02-18
Hungary
 

I am actually modifying the product view’s phtml and want to display specific static CMS blocks depending on an attribute of the product. The resulting HTML would then be put in to a ThickBox and displayed when the user clicks on a link inside the view page.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Kara Heinrichs
Guru
 
Avatar
Total Posts:  482
Joined:  2008-01-17
aa, mi, us
 

This is an example that adds kickers or promo banners defined in a static block to the bottom of the home page.  Your mileage may vary.

In the XML file that outputs the HTML (this example in page.xml) add the reference to the static block:

<default>
   <
block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">
       ...
      <
block type="core/text_list" name="bottom" as="bottom" /></block>
   </
block>
   <
reference name="bottom">
      <
block type="cms/block" name="home_banners">
         <
action method="setBlockId"><block_id>home_banners</block_id></action>
      </
block>
   </
reference>
</default>

In the default page PHTML file referenced (in this example 3columns.phtml) add the div to hold and style the static block:

<div class="bottom">
     
<?=$this->getChildHtml('bottom')?>
</div>

In the admin system, add the static block content:
Identifier: home_banners (in this example)

Hit refresh and pray.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Sintax
Member
 
Total Posts:  58
Joined:  2008-02-18
Hungary
 

Thx. But the solution you mentioned assumes that I know ALL the static blocks before deploying the store. What I want is to “map” a static CMS block to an attribute option value. I managed to map get the list of possible values for the given attribute, I created a separate table to store the relationships and a custom form to match them. Now my only problem is to get the content out of the CMS block (instead of running DB queries)

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

Ok, so i’m guessing that you want to insert cms block html in catalog/product/view.phtml file?

In that case, if you have product custom attribute ‘cms_block’:

<?=$this->getLayout()->createBlock('cms/block')->setBlockId($_product->getCmsBlock())->toHtml()?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
taavi
Jr. Member
 
Total Posts:  10
Joined:  2008-04-13
 

Hello, I didn’t want to make a new topic becuse my question is related to this one.

I’ll explain what I would like to do (but don’t know how): I have created a page under “CMS->Static blocks” with the Identifier “footer”. I would like to display its contents (bunch of HTML code) into the specific div on the page.

I don’t want to make any referances but just something like this: add <block type="cms/block" name="footer"> into page.xml and in the 2columns-left.phtml I add <?=$this->getChildHtml('footer')?> to the spot I want so it will display the static blocks contents.

I cannot get this to work. I have read and searched the forums and knowledge base but found nothing that would help me so far. Maybe it’s just me.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top