Magento Forum

   
Page 1 of 4
Static Blocks and Callout boxes ? 
 
Ronaldr
Sr. Member
 
Avatar
Total Posts:  124
Joined:  2008-08-21
California
 

Static Blocks:

So from what I understand static blocks are displayed in a category view or a CMS page and is written in html. Also, from what I’ve seen in the magento static block tutorial, The block is typically just a image link with a clickable link attached to the image. I also saw during the video, him put together a 3 static block landing page called “electronics 2”. In this example he used html in a more conventional sense, but failed to really show the code.

For Refrence: Magento Static Block Screencast

Questions About Static Blocks:

1) Where are the static block files you create stored on the server ?

2) Are there code examples, or templates for the more conventional html static blocks ?

Callouts:

Callout Boxes appear to just be images, they are only displayed on the left and right columns of a page, and grouped with some of the various features of the site (e.g. compare, polls, my cart, ect,)

Questions About Callouts:

1) Where are the Callout files stored on the server ?

2) How to position the callout boxes ?

Any suggestions will be greatly appreciated!

 
Magento Community Magento Community
Magento Community
Magento Community
 
joyously
Guru
 
Total Posts:  447
Joined:  2008-08-21
 

The static blocks are stored in the database, not as files on the server.
The demo store has a couple of static block examples. Log in as admin to see them. I think the home page has the “New Products” block, which is pretty useful and shows the syntax for how to use a block in a page.
I modified my email templates to use static blocks, so that just changing one block can affect all the emails.  It would be nice if the default theme used this approach for things like “Store Name” and “Customer Service Message” so not only could we see how to do it, but it would make it easier to change the text Magento Demo Store everywhere and the store phone number too.

The callouts are hardcoded in the default layout xml to be files on your server.  I think you can change them to be static blocks instead, so you can manipulate them in the admin instead of in the layout files.
Update:
I got my head wrapped around how to do this now.
In the default theme, the catalog.xml file has this for the left callout:

<reference name="left">
      <
block type="core/template" name="left.permanent.callout" template="callouts/left_col.phtml">
          <
action method="setImgSrc"><src>images/media/col_left_callout.jpg</src></action>
          <
action method="setImgAlt" translate="alt" module="catalog"><alt>Our customer service is available 24/7. Call us at (800DEMO-NUMBER.</alt></action>
          <
action method="setLinkUrl"><url>checkout/cart</url></action>
      </
block>
  </
reference>
I changed it to this:
<reference name="left">
      <
block type="cms/block" name="left.permanent.callout">
          <
action method="setBlockId"><block_id>left_column_block</block_id></action>
      </
block>
  </
reference>
and added a CMS Static Block with an ID of left_column_block. I can put whatever I want in there from the backend(including empty) and it will show in the left column. I did the same thing with the right column, and can add more in strategic places for future editing by the client in the backend.  This worked even when I hadn’t created the static block yet (no errors shown and no block shown).

 
Magento Community Magento Community
Magento Community
Magento Community
 
DetailAddict
Jr. Member
 
Total Posts:  23
Joined:  2008-10-16
 

NICE!  Thank you VERY much!  Exactly what I am looking for! smile I hate having to hack around code to get things done.  Now I just have to do this once and change to whatever I want later and from time to time. smile

joyously - 18 September 2008 07:36 AM

The static blocks are stored in the database, not as files on the server.
The demo store has a couple of static block examples. Log in as admin to see them. I think the home page has the “New Products” block, which is pretty useful and shows the syntax for how to use a block in a page.
I modified my email templates to use static blocks, so that just changing one block can affect all the emails.  It would be nice if the default theme used this approach for things like “Store Name” and “Customer Service Message” so not only could we see how to do it, but it would make it easier to change the text Magento Demo Store everywhere and the store phone number too.

The callouts are hardcoded in the default layout xml to be files on your server.  I think you can change them to be static blocks instead, so you can manipulate them in the admin instead of in the layout files.
Update:
I got my head wrapped around how to do this now.
In the default theme, the catalog.xml file has this for the left callout:

<reference name="left">
      <
block type="core/template" name="left.permanent.callout" template="callouts/left_col.phtml">
          <
action method="setImgSrc"><src>images/media/col_left_callout.jpg</src></action>
          <
action method="setImgAlt" translate="alt" module="catalog"><alt>Our customer service is available 24/7. Call us at (800DEMO-NUMBER.</alt></action>
          <
action method="setLinkUrl"><url>checkout/cart</url></action>
      </
block>
  </
reference>
I changed it to this:
<reference name="left">
      <
block type="cms/block" name="left.permanent.callout">
          <
action method="setBlockId"><block_id>left_column_block</block_id></action>
      </
block>
  </
reference>
and added a CMS Static Block with an ID of left_column_block. I can put whatever I want in there from the backend(including empty) and it will show in the left column. I did the same thing with the right column, and can add more in strategic places for future editing by the client in the backend.  This worked even when I hadn’t created the static block yet (no errors shown and no block shown).

 
Magento Community Magento Community
Magento Community
Magento Community
 
DetailAddict
Jr. Member
 
Total Posts:  23
Joined:  2008-10-16
 

I would imagine we can do the same with header as well since the footer is already as a block. smile This is very cool. smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vicky
Member
 
Avatar
Total Posts:  50
Joined:  2008-09-28
 

Thank you so much for this!  I was updating the XML files but this makes it so much easier to find.  Plus I wont have to worry about too many changes to the core file.

Works like a charm.

 
Magento Community Magento Community
Magento Community
Magento Community
 
BobMane
Sr. Member
 
Total Posts:  108
Joined:  2008-07-30
 

Sorry, can you please post the code to change the “right” side as well?

 
Magento Community Magento Community
Magento Community
Magento Community
 
DetailAddict
Jr. Member
 
Total Posts:  23
Joined:  2008-10-16
 

hmmm....  it doesn’t work for me… :(
heck, I can’t even get rid of that stupid DEMO-NUMBER image....  can someone provide the full path to the catalog.xml?  Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
joyously
Guru
 
Total Posts:  447
Joined:  2008-08-21
 

@DetailAddict:  You might have more trouble with the headers because of the dynamic nature of them. This is for static blocks, you know.

@BobMane:  For the right side mine looks like this:

<reference name="right">
      <
block type="core/template" before="cart_sidebar" name="catalog.compare.sidebar" template="catalog/product/compare/sidebar.phtml"/>
      <
block type="core/template" name="right.permanent.callout">
          <
action method="setBlockId"><block_id>right_column_block</block_id></action>
      </
block>
  </
reference>
and I name the static block “right_column_block”.

@DetailAddict: Make sure you aren’t having a cache issue (turn caching off until you’ve got your store working). You can find the catalog.xml file in app/design/frontend/default/yourtheme/layout

 
Magento Community Magento Community
Magento Community
Magento Community
 
saileruk
Jr. Member
 
Avatar
Total Posts:  25
Joined:  2008-08-21
 
joyously - 21 October 2008 09:22 AM

@DetailAddict:  You might have more trouble with the headers because of the dynamic nature of them. This is for static blocks, you know.

@BobMane:  For the right side mine looks like this:

<reference name="right">
      <
block type="core/template" before="cart_sidebar" name="catalog.compare.sidebar" template="catalog/product/compare/sidebar.phtml"/>
      <
block type="core/template" name="right.permanent.callout">
          <
action method="setBlockId"><block_id>right_column_block</block_id></action>
      </
block>
  </
reference>
and I name the static block “right_column_block”.

@DetailAddict: Make sure you aren’t having a cache issue (turn caching off until you’ve got your store working). You can find the catalog.xml file in app/design/frontend/default/yourtheme/layout

joyously,thanks a lot for your code. It does help.
But it only works on the left, not on the right. Any idea? I think maybe we need do some change on other files, for example, right_col.phtml. Then we can make this happen on the right as well.

 
Magento Community Magento Community
Magento Community
Magento Community
 
joyously
Guru
 
Total Posts:  447
Joined:  2008-08-21
 
saileruk - 01 November 2008 10:12 AM

joyously,thanks a lot for your code. It does help.
But it only works on the left, not on the right. Any idea? I think maybe we need do some change on other files, for example, right_col.phtml. Then we can make this happen on the right as well.

The concept is the same regardless of where you do it. I did forget that I had previously changed my right column template to be the same as left (or vice versa ... I forget which one was generic to begin with).

 
Magento Community Magento Community
Magento Community
Magento Community
 
jofgav
Jr. Member
 
Avatar
Total Posts:  30
Joined:  2008-04-09
UK
 

Nice one.
One thing I’ve noticed is that you must also add the “getChildHtml(’YourStaticBlockId‘)” code if you plan to call your static block within a .phtml file
For example I wanted to add a second menu to the header so I created a static block with the identifier of cmsLinks (this step has been covered above). I then had to do the following before it worked:-
1. Modified /app/design/frontend/default/MyTemplateName/layout/page.xml to include:-

<block type="page/html_header" name="header" as="header">
    ...
    <
block type="cms/block" name="cmsLinks">
        <
action method="setBlockId"><block_id>cmsLinks</block_id></action>
    </
block>
</
block>
2. Modified /app/design/frontend/default/MyTemplateName/template/page/html/header.phtml to include:-
<div class="cmsLinks"><?php echo $this->getChildHtml('cmsLinks'?></div>

 
Magento Community Magento Community
Magento Community
Magento Community
 
aneeshvs
Jr. Member
 
Total Posts:  13
Joined:  2008-10-22
 

Hi,

Any idea to display the callout boxes in the content(center column) out of the left or right blocks??

How can I get these boxes where ever I want(say in the view.phtml file wich is used to display the product details)?

Regards,
Aneesh

 
Magento Community Magento Community
Magento Community
Magento Community
 
joyously
Guru
 
Total Posts:  447
Joined:  2008-08-21
 

I figured out today how to get a block from a template. Here’s what I put at the top of my contacts template.

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('email_contact_us')->toHtml() ?>
I had already made a static block called email_contact_us that I reference in all of the email templates, so there is just one place to change it (in the backend). Now I use that same static block to get the message on the Contact Us page.  The should work for any block and template combination, since the default templates do it all over the place.
You would need to use
<?php echo $this->getLayout()->createBlock('whatever/yourblockis')->setTemplate('whatever/yourtemplateis.phtml')->toHtml() ?>

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mendrel
Jr. Member
 
Total Posts:  23
Joined:  2008-11-05
 

Sweet. Adding static blocks to main CMS pages is easy. Putting them at the top of a category or a product is cool...but how could you insert a static block within the ‘content’ of a product. For example, I have a list of colors for some products, rather than paste in the table for each product, I’d rather include a static block. That way, I can update the content in one place rather than many. However, trying to call a static block within a product description doesn’t work. It just shows the static block call...any suggestions?

 
Magento Community Magento Community
Magento Community
Magento Community
 
saileruk
Jr. Member
 
Avatar
Total Posts:  25
Joined:  2008-08-21
 
joyously - 19 November 2008 12:34 PM

I figured out today how to get a block from a template. Here’s what I put at the top of my contacts template.

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('email_contact_us')->toHtml() ?>
I had already made a static block called email_contact_us that I reference in all of the email templates, so there is just one place to change it (in the backend). Now I use that same static block to get the message on the Contact Us page.  The should work for any block and template combination, since the default templates do it all over the place.
You would need to use
<?php echo $this->getLayout()->createBlock('whatever/yourblockis')->setTemplate('whatever/yourtemplateis.phtml')->toHtml() ?>

hehehe, works again. joyously, thank you so much. wanna hug you LOL

 
Magento Community Magento Community
Magento Community
Magento Community
 
joyously
Guru
 
Total Posts:  447
Joined:  2008-08-21
 
Mendrel - 19 November 2008 02:36 PM

Sweet. Adding static blocks to main CMS pages is easy. Putting them at the top of a category or a product is cool...but how could you insert a static block within the ‘content’ of a product. For example, I have a list of colors for some products, rather than paste in the table for each product, I’d rather include a static block. That way, I can update the content in one place rather than many. However, trying to call a static block within a product description doesn’t work. It just shows the static block call...any suggestions?

I explained on another thread how you can use this same thing in a template to show a static block for an attribute of your product.  If it’s the same for all of your products, just hard code it in the template. But if it changes per product, make an attribute to hold the name of the static block to display and then in the template you substitute the attribute value into the block_id of the static block call.

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