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

Page 1 of 2
How to call a static block from template files? 
 
Rslonik
Jr. Member
 
Total Posts:  1
Joined:  2007-12-04
 

Hi!

Simple question: How to call a static block in footer.phtml?

I use the default theme. My footer have just this line:

<?php echo $this->getChildHtml('footer_links'?>

As you can see, some links appear on footer:
http://essencia.nexcess.net/

But it IS NOT my footer_links block!! I don’t know from where those links came O_O
Can be cache thing? I’ve already disabled, refreshed, re-enabled but nothing helped.

(I could put my html directly in the footer.phtml, but I want to use the static block feature instead)

So, How to call a static block in footer.phtml?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rooni
Sr. Member
 
Total Posts:  87
Joined:  2009-03-25
England
 

i am also looking for answer for this question

 
Magento Community Magento Community
Magento Community
Magento Community
 
ikuzyk
Magento Team
 
Avatar
Total Posts:  60
Joined:  2007-08-09
Ternopil, Ukraine
 

to add a static block into footer.phtml:
1) add a new static block (in this example Identifier is my_footer_block)
2) layout/page.xml in:

<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
add a:
<block type="cms/block" name="my_footer_block"><action method="setBlockId"><block_id>my_footer_block</block_id></action></block>
so in this example it will looks like:
<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
                <
block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/>
                <
block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/>
                <
block type="cms/block" name="my_footer_block"><action method="setBlockId"><block_id>my_footer_block</block_id></action></block>
</
block>
3) in footer.phtml - comment default links and add your block call:
<div class="informational">
    
<?php //echo $this->getChildHtml() ?>
    
<?php echo $this->getChildHtml('my_footer_block'?>
</div>

PS. but to add a link to your footer links you can always use this construction:

<reference name="footer_links">
          <
action method="addLink" translate="label title"><label>Your Path</label><url>your/path/</url><title>Your Path</title></action>
</
reference>

hope its help smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Unixversal
Sr. Member
 
Avatar
Total Posts:  80
Joined:  2008-04-23
Cologne, Germany
 

Thx Igor that worked perfectly and helped a lot! Excactly what I was searching for grin

Cheers.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jirka66666
Jr. Member
 
Total Posts:  18
Joined:  2009-05-20
 

And is this solution also good?

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

 
Magento Community Magento Community
Magento Community
Magento Community
 
ikuzyk
Magento Team
 
Avatar
Total Posts:  60
Joined:  2007-08-09
Ternopil, Ukraine
 
jirka66666 - 27 July 2009 09:19 PM

And is this solution also good?

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

Yes, this work too.
When you starting new theme - better use first solution, and on customization final steps (for little callouts, etc) you can use second.
Magento is very flexible wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
Pagayo
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2008-09-07
Netherlands
 

Hi,

I also want something like this in but than in my view.phtml. I also would like to have this info flexible using an attribute. For example; I have made two attributes called “nike_info” and “adidas_info”. I also made two static blocks called “nike_info” and “adidas_info”.

Now I would like to have the static block called “adidas_info” to only pop up in an product that has the attribute “adidas_info”. And for the nike product to only show the “nike_info”, as you probably would have guest.

I have succefully done this with images using this;

<img src="media/images/checkoutbutton-<?php echo $_helper->productAttribute($_product, nl2br($_product->getShopName()), 'shop_name') ?>.jpg"></img>

But for the static block I can not do this;

<?php
echo $this->getLayout()
->createBlock(’cms/block’)
->setBlockId(’banner-productview-<?php echo $_helper->productAttribute($_product, nl2br($_product->getShopName()), 'shop_name') ?>’)
->toHtml() ?>

I could really use any help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dannyz1984
Sr. Member
 
Avatar
Total Posts:  153
Joined:  2009-04-12
 
Pagayo.com - 03 August 2009 10:34 AM

Hi,

I also want something like this in but than in my view.phtml. I also would like to have this info flexible using an attribute. For example; I have made two attributes called “nike_info” and “adidas_info”. I also made two static blocks called “nike_info” and “adidas_info”.

Now I would like to have the static block called “adidas_info” to only pop up in an product that has the attribute “adidas_info”. And for the nike product to only show the “nike_info”, as you probably would have guest.

I have succefully done this with images using this;

<img src="media/images/checkoutbutton-<?php echo $_helper->productAttribute($_product, nl2br($_product->getShopName()), 'shop_name') ?>.jpg"></img>

But for the static block I can not do this;

<?php
echo $this->getLayout()
->createBlock(’cms/block’)
->setBlockId(’banner-productview-<?php echo $_helper->productAttribute($_product, nl2br($_product->getShopName()), 'shop_name') ?>’)
->toHtml() ?>

I could really use any help.

hi

try to assign a variable $productView to

$_helper->productAttribute($_productnl2br($_product->getShopName()), 'shop_name')

and concat that variable with string to another variable

$productBanner 'banner-productview-' $productView

so final piece of code can be:

setBlockId('$productBanner')

sorry i am not an expert programmer but try and see if that works?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Pagayo
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2008-09-07
Netherlands
 

Hi pharmokan,

Thanks for your info. We could use it very well. We came up with this and it works very well now.

First.

<!-- Create Variable for Attribute"ShopName"--> <?php $affname $_helper->productAttribute($_productnl2br($_product->getShopName()), 'shop_name'?>

Than

<div class="collateral-box"> <div class="description-box"> <br> <!-- CALL: Static Block "banner-ShopName" --> <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('banner-' $affname)->toHtml() ?> </div></div>

Thabks for your help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
kasigratis
Member
 
Avatar
Total Posts:  46
Joined:  2009-09-18
Denpasar
 
Igor Kuzyk - 21 July 2009 08:32 AM

to add a static block into footer.phtml:
1) add a new static block (in this example Identifier is my_footer_block)
2) layout/page.xml in:

<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
add a:
<block type="cms/block" name="my_footer_block"><action method="setBlockId"><block_id>my_footer_block</block_id></action></block>
so in this example it will looks like:
<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
                <
block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/>
                <
block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/>
                <
block type="cms/block" name="my_footer_block"><action method="setBlockId"><block_id>my_footer_block</block_id></action></block>
</
block>
3) in footer.phtml - comment default links and add your block call:
<div class="informational">
    
<?php //echo $this->getChildHtml() ?>
    
<?php echo $this->getChildHtml('my_footer_block'?>
</div>

PS. but to add a link to your footer links you can always use this construction:
<reference name="footer_links">
          <
action method="addLink" translate="label title"><label>Your Path</label><url>your/path/</url><title>Your Path</title></action>
</
reference>

hope its help smile

I doesn’t work for me.
Anything wrong?
I already did the same like yours..

 
Magento Community Magento Community
Magento Community
Magento Community
 
varker
Jr. Member
 
Total Posts:  22
Joined:  2010-02-25
 
Igor Kuzyk - 28 July 2009 05:53 AM

jirka66666 - 27 July 2009 09:19 PM
And is this solution also good?

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

Yes, this work too.
When you starting new theme - better use first solution, and on customization final steps (for little callouts, etc) you can use second.
Magento is very flexible wink

Thanks jirka66666 and Igor - great posts, very helpful!

 
Magento Community Magento Community
Magento Community
Magento Community
 
toys_online
Jr. Member
 
Total Posts:  14
Joined:  2010-11-02
 

My footer links are working fine. But I am trying to add a static block for some pages which would be footer text that appears under the footer links.

So I created a static block and on the page where i wanted it to appear, I added this as the custom xml layout update. This way I got the block to appear only on the pages that I wanted it to appear on.

<reference name="footer"> <block type="cms/block" name="toy-story-page-footer-block"> <action method="setBlockId"><block_id>toy-story-page-footer-block</block_id></action> </block> </reference>

All this was done via the admin, no change in codes.

But all of a sudden, none of the footer blocks seem to appear, I haven’t changed any settings. I use filezilla for ftp and I may have accidentally moved some folders, I am trying to figure out if I did or not.

Have been trying to fix this for the past month and have read every forum possible.

Any help will be really appreciated.

link here - tiny toys

 
Magento Community Magento Community
Magento Community
Magento Community
 
MageClub
Guru
 
Avatar
Total Posts:  386
Joined:  2009-07-25
India
 

Hi Igor,

Lets say, we just need this static block to show on our homepage and no anywhere else , then what do we do ?

Let me know please.

Igor Kuzyk - 21 July 2009 08:32 AM

to add a static block into footer.phtml:
1) add a new static block (in this example Identifier is my_footer_block)
2) layout/page.xml in:

<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
add a:
<block type="cms/block" name="my_footer_block"><action method="setBlockId"><block_id>my_footer_block</block_id></action></block>
so in this example it will looks like:
<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
                <
block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/>
                <
block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/>
                <
block type="cms/block" name="my_footer_block"><action method="setBlockId"><block_id>my_footer_block</block_id></action></block>
</
block>
3) in footer.phtml - comment default links and add your block call:
<div class="informational">
    
<?php //echo $this->getChildHtml() ?>
    
<?php echo $this->getChildHtml('my_footer_block'?>
</div>

PS. but to add a link to your footer links you can always use this construction:
<reference name="footer_links">
          <
action method="addLink" translate="label title"><label>Your Path</label><url>your/path/</url><title>Your Path</title></action>
</
reference>

hope its help smile
 
Magento Community Magento Community
Magento Community
Magento Community
 
MageClub
Guru
 
Avatar
Total Posts:  386
Joined:  2009-07-25
India
 

I did it my way and it works good, but its showing on all pages when I do my hack.

Havent tried Igor’s , since his hack is almost the same as ours.

toys_online - 11 May 2011 07:41 PM

My footer links are working fine. But I am trying to add a static block for some pages which would be footer text that appears under the footer links.

So I created a static block and on the page where i wanted it to appear, I added this as the custom xml layout update. This way I got the block to appear only on the pages that I wanted it to appear on.

<reference name="footer"> <block type="cms/block" name="toy-story-page-footer-block"> <action method="setBlockId"><block_id>toy-story-page-footer-block</block_id></action> </block> </reference>

All this was done via the admin, no change in codes.

But all of a sudden, none of the footer blocks seem to appear, I haven’t changed any settings. I use filezilla for ftp and I may have accidentally moved some folders, I am trying to figure out if I did or not.

Have been trying to fix this for the past month and have read every forum possible.

Any help will be really appreciated.

link here - tiny toys

 
Magento Community Magento Community
Magento Community
Magento Community
 
TonyBrownDev
Jr. Member
 
Total Posts:  12
Joined:  2011-04-25
 

Very simple!

You will create a new static block with a block name and block identifier. The identifier will be used in the next steps.

Once you have created your CMS Static Block, you will need to select the template file you would like to modify. I will select the success page to add in some thank you verbage to display when the user makes a purchase.

To do this, simply open app\\design\\frontend\\base\\default\\template\\checkout\\success.phtml with your favorite text editor.

When this is open, add in the following bit of code to the page, wherever you would like your block to display:
<?php echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘block_identifier’)->toHtml(); ?>

To reference the block you want, change the ‘block identifier’ to whatever your cms block’s name is. For example, if the cms block identifier was success_page. I would change this to display:
<?php echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘success_page’)->toHtml(); ?>

Save the page and that is it! You have successfully added a CMS Static Block onto the success page in Magento!

Reference: http://magentotools.wordpress.com/2012/06/07/reference-static-block-in-magento/

 
Magento Community Magento Community
Magento Community
Magento Community
 
magentotalk
Jr. Member
 
Total Posts:  11
Joined:  2013-01-03
 

And is this solution also good?

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

This will works.....

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2