So I scoured the interwebs looking for this answer and finally pieced it together…so I’m saving it here for my own posterity. I found lots of results for embedding the blocks in other CMS pages but if you are working in the .phtml and .xml files then you’d have some reading to do just to get it to work.
Step 1:
Create your static block in the admin area of Magento. (CMS > Static Blocks) Click on ‘+ Add New Block’. The ‘Identifier’ is what you’ll need to take note of for embedding the block.
Step 2:
Navigate your way to the layout folder. (app > design > frontend > default > your_theme > layout) Open the file that references the page you intend to put the block into. In my case ‘page.xml’.
Step 3:
Find the spot in the .xml where you would like your block to appear and insert the following code where xxxxxx is the ‘Identifier’ you set earlier when creating your block.
xxxxxx
Step 4:
Navigate your way to the template folder (app > design > frontend > default > your_theme > template) Open the file that you would like the block to appear in and insert the following code in the appropriate position where xxxxxx is the ‘Identifier’ you set earlier when creating your block.
echo $this->getChildHtml('xxxxxx'); Finale:
That should do it. If not, I’m sure something is wrong and I suggest you keep scouring the internet and let me know what you find. Of course if there are any questions I’ll do all I can to answer them. Not sure how much help I can be since I struggled with this so much (hence the suggestion to continue scouring) but I’ll try.
Additional Information
From: Ina Code Blog
Go to Magento admin uder CMS -> Static Blocks and Add New Block. Insert Block Title, Identifier (for example: my-new-block), set Status to Enabled, insert block Content and Save Block.
If you want to put your static block in left column open file /app/design/frontend/your_theme/your_theme/template/callouts/left_col.phtml and insert code below where you want the static block to apear:
echo $this->getLayout()->createBlock('cms/block')->setBlockId('my-new-block')->toHtml(); You can put this code wherever you want the block to apear, for exapmle right_col.phtml, 3columns.phtml, … Sky is your limit …
Hi, there’s also a simpler method detailed in
http://www.inacode.com/magento/magento-add-static-block
You can just
getLayout()->createBlock(’cms/block’)->setBlockId(‘my-new-block’)->toHtml() ?>
But your method is cleaner. Just wanted to let you know.
Sweet, thanks.
Never looked that far into it. Unfortunately I never got far enough into the project at my previous employer to need to.
I’ve been digging around for longer than I’d like to admit trying to get this working. Thank you for this simple walk through. You saved my sanity.
I’ve been going nuts trying to find this. Have you figured out how to call up a static block from a product detail page dynamically?
i done in the same manner u told above but it does not worked for me
i am adding the code in page.xml but if i add another code in catalog.xml the tricks worked
i just want to know how can i know the blocks are calling from page.xml or not.
thanks
Vaseem
Hey Vaseem, It’s been quite a while since I had to deal with Magento but I’d love to try to help.
If I understand you correctly, you probably have two templates. One for pages and one for pages IN the catalog. If you’re wanting your static block to show up on a catalog page then it will have to be in your category template.
Thank you very much for this nice explanation. The more i learn about Magento the more i like it and the way how it is organized.
How can I achieve the reverse of this and use my static block to call out to a phtml for some html content generated by PHP echos. What I really want to do is use the translation feature in the static block but the only way I can think of doing this is to call out to a phtml file which then calls the translation and displays translated text back into the static block and onto my webpage.
That’s a good question. Not something that I experienced in my short time of dealing with Magento. Anyone else have any suggestions?
Nice and clean post
Like it.
Thanks for posting this. It is very helpful in doing something that ‘should’ be very easy and straight forward. You’re a life saver.
This is very straight and easy way, better then the xml based configuration. I think the xml has indeed complicated magento. I have been searching for a while until I found your simple solution. Sometimes the answer is under our noses without realizing it. Thanks for this post.
What if I have several blocks with the same name for different storeviews? Is there a way to pass storeId and enforce that a block for a specific storeId is shown? (This is necessary in the backend where no storeId is available but has to be gotten from order.)
While I’m not so well versed on Magento as I used to be I would assume that you might be able to include a
switchor series ofifstatements to try and filter the results. Or perhaps naming the blocks using thestoreIdas part of the name and then referencing thestoreIdin when you call the block. These are things that I might have tried in other types of software.