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

Tutorial: Getting multiple CMS areas with a single $this->getCmsBlockHtml()
 
HAL10001
Member
 
Avatar
Total Posts:  52
Joined:  2008-06-02
Ann Arbor, MI
 

I could not find this anywhere, so I figured I would post it here so that others would have access to it through the forums. I will not be placing it on the wiki, but if you wanted to, then feel free to do so. There are two ways to accomplish this, but I will be highlighting the easiest.

We have a need to use Google Web Optimizer and Omniture’s Test & Target on projects, but in order to accurately test, it really requires that you setup several CMS areas. In Magento’s demo, the Electronics landing page is only a single static block, with all the content placed into a content area. This is primarily because if you look in your directory structure for the codebase, app/design/frontend/default/default/template/catalog/category/view.phtml only has a single call to $this->getCmsBlockHtml() for each display mode. It makes sense for the demo they would only show the simplest example.

In order to use that single CMS block, and split it up into multiple (and separately adminable) CMS blocks, first go to CMS > Static Blocks in the admin. Create a block, and call it something like My Category Landing Page. Inside the content area, you can create references to other static blocks. For instance, your content could look like this:

<div>
{{block type="cms/block" block_id="my_category_landing_page_area_1"}}
</div>
<
div>
{{block type="cms/block" block_id="my_category_landing_page_area_2"}}
</div>
<
div>
{{block type="cms/block" block_id="my_category_landing_page_area_3"}}
</div>

Now after saving this static block, go back to CMS > Static Blocks, and create three more static blocks, each with the block id you chose to use in your “parent block” content area. When you create a category under Catalog > Manage Categories, choose “Static block only” or “Static block and products”, and then choose My Category Landing Page as the Static Block. You will then have one CMS static block, that is actually a combination of multiples, all of them distinct.

As a bonus, you can also mix in dynamic content you create that is not adminable, but still referenced from the parent static block. We created a left-hand dynamic navigation structure that was intermixed with our CMS, and wanted to reference it from the static block as opposed to embedding it into the PHTML view itself, so you can also do something like the following:

<div>
{{block type="cms/block" block_id="my_category_landing_page_area_1"}}
</div>
<
div>
{{block type="cms/block" block_id="my_category_landing_page_area_2"}}
</div>
<
div>
{{block type="cms/block" block_id="my_category_landing_page_area_3"}}
</div>
<
div>
{{block type="catalog/navigation" template="catalog/navigation/subnav.phtml"}} 
</div>

That I am aware of, you can embed just about any block type, and just reference the template. This provides you with a lot of flexibility with a single CMS block reference. One thing to note is that the block type appears to determine what functionality is available to you in the template you reference. If the type was not catalog/navigation, then I would not be able to properly get categories. So, if you are thinking you might want more functionality, it would be best to build your HTML structure in the primary static block, and then reference multiple block types and templates.

I hope this was helpful.

 
Magento Community Magento Community
Magento Community
Magento Community
 
carconper
Jr. Member
 
Total Posts:  1
Joined:  2009-02-23
 

Thank you very much for the Tip. I wasnt looking for it but it can be really useful for me ina future

I have one question about the method getCmsBlockHtml (). Which is exactly its functionality? I mean, which CMS block does the method refer to? If you have more than one block defined which one it will take?

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