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.
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 ?
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 (800) DEMO-NUMBER.</alt></action> <action method="setLinkUrl"><url>checkout/cart</url></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).
NICE! Thank you VERY much! Exactly what I am looking for! 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.
joyously - 18 September 2008 08: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 (800) DEMO-NUMBER.</alt></action> <action method="setLinkUrl"><url>checkout/cart</url></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).
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.
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!
@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
@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.
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).
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:-
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
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 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
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.