Call-back icon  Enterprise Sales: +1.310.775.2674 (N. America)   +44 20.3286.4137 (UK)

Magento

eCommerce Software for Online Growth

Magento Forum

   
Page 1 of 4
static blocks in left / right column on home page? 
 
cshontz
Sr. Member
 
Avatar
Total Posts:  85
Joined:  2007-11-07
 

Can someone provide me with a “Hello World” example of how to add an HTML box to the left (or right) column in the default 3-column home page?

 
Magento Community Magento Community
Magento Community
Magento Community
 
cshontz
Sr. Member
 
Avatar
Total Posts:  85
Joined:  2007-11-07
 

C’mon… how hard can it be?

 
Magento Community Magento Community
Magento Community
Magento Community
 
sherrie
Mentor
 
Avatar
Total Posts:  1080
Joined:  2007-12-14
Illinois, USA
 

Try this:
http://www.magentocommerce.com/media/screencasts/static-blocks/view

 Signature 

Creativity is falling in love with the world. – Dewitt Jones
Current Projects: Aqua Gear Direct & IHSA State Finals + Pickup at Event/Multiple Flatrates • Running: PHP 5.2.5/MySQL 5.0.45/Magento 1.3.2.1 on HostGator

 
Magento Community Magento Community
Magento Community
Magento Community
 
cshontz
Sr. Member
 
Avatar
Total Posts:  85
Joined:  2007-11-07
 

Okay, I see “left_col.phtml”, and “right_col.phtml”, and I see how these are referenced in “catalog.xml”.

I’m still unsure, because this content seems to be outside the scope of the “static block” model - correct me if I’m wrong. Or… maybe I’m just not thinking outside the box. Heh.

So hard-code “left_col” and “right_col” phtml files, basically?

 
Magento Community Magento Community
Magento Community
Magento Community
 
cshontz
Sr. Member
 
Avatar
Total Posts:  85
Joined:  2007-11-07
 
sherrie - 10 April 2008 08:34 AM

Try this:
http://www.magentocommerce.com/media/screencasts/static-blocks/view

Thanks, Sherrie. I’ve watched that a few times now. The problem with the screencast is that it applies the static block to a category - which I think I understand. From the screencast, it looks like you can specify which column the static block appears in.

However, I want to add the static block to the home page, before a category is selected, and there doesn’t seem to be a means to do so using the admin UI.

What is the syntax for inserting a static block into a phtml file? Is that possible?

 
Magento Community Magento Community
Magento Community
Magento Community
 
sherrie
Mentor
 
Avatar
Total Posts:  1080
Joined:  2007-12-14
Illinois, USA
 

Probably, I honestly haven’t gotten that far yet - I just posted the link because I knew it was there.

 Signature 

Creativity is falling in love with the world. – Dewitt Jones
Current Projects: Aqua Gear Direct & IHSA State Finals + Pickup at Event/Multiple Flatrates • Running: PHP 5.2.5/MySQL 5.0.45/Magento 1.3.2.1 on HostGator

 
Magento Community Magento Community
Magento Community
Magento Community
 
alistek
Sr. Member
 
Total Posts:  293
Joined:  2008-04-02
Normal, IL
 

So I just typed up a huge reply to this and somehow it was lost, so here goes again.

If you want to add a CMS Static block to a page you need to be somewhat familiar with layouts.  Layouts are stored in:

app/design/frontend/default/default/layout

This directory contains quite a few XML files.  These files determine what blocks are shown in the default structural .phtml files.

The first step is to create the block we would like to add to a page.  In the Admin section go to the CMS menu and select Static Blocks and create a new block.

Settings:
Name: Test Block
Identifier: test_block (this is what we will refer to in the code)
Status: enabled
Content: This is some text.

The second step is to find the XML file containing the layout we wish to modify.  Let’s say we would like to make this block appear only on the Customer Account page (the customer dashboard).  We would find the customer.xml file and add some text to it.  There are a few things to know about layouts first.

A very basic structure is something like this:

/** If the code you are placing is under default it will appear on all pages unless specifically <unset>, this allows you to put something under the reference tag and have it appear on every page. **/
<default>
/** The reference name will refer to what section we are placing the block in, i.e. if the name="header" it will be in the header section.  Likewise saying name="content" will place it in the main content section **/
<reference name="header">
/** Some block we have added **/ 
<block></block>
</
reference>
</default>

/** If a section is under a different name such as customer_account it will pertain only to that section **/
<customer_account>
<
reference name="header">
<
block></block>
</
reference>
</
customer_account>

Now if we place out code in the customer.xml file under the section:

<!--
Customer account home dashboard layout
-->

    <
customer_account_index>
        <
update handle="customer_account"/>
        <!-- 
Mage_Customer -->
        <
reference name="root">
            <
action method="setTemplate"><template>page/1column.phtml</template></action>
        </
reference>
        <
reference name="content">
            <
block type="customer/account_dashboard" name="customer_account_dashboard" template="customer/account/dashboard.phtml">
                <
block type="customer/account_dashboard_hello" name="customer_account_dashboard_hello" as="hello" template="customer/account/dashboard/hello.phtml"/>
                <
block type="core/template" name="customer_account_dashboard_top" as="top" />
                <
block type="customer/account_dashboard_info" name="customer_account_dashboard_info" as="info" template="customer/account/dashboard/info.phtml"/>
                <
block type="customer/account_dashboard_newsletter" name="customer_account_dashboard_newsletter" as="newsletter" template="customer/account/dashboard/newsletter.phtml"/>
                <
block type="customer/account_dashboard_address" name="customer_account_dashboard_address" as="address" template="customer/account/dashboard/address.phtml"/>
                <
block type="core/template" name="customer_account_dashboard_info1" as="info1" />
                <
block type="core/template" name="customer_account_dashboard_info2" as="info2" />
/** ------------------------------------------------------------------------------------------------------------------------------------- **/
            
<block type="cms/block" name="cms_test_block">
                <
action method="setBlockId"><block_id>test_block</block_id></action>
            </
block>
/** ------------------------------------------------------------------------------------------------------------------------------------- **/
            
</block>
        </
reference>

    </
customer_account_index>

It will appear at the end of the Customer Dashboard.  Note the <block_id></block_id> tags, whatever we put there will correspond to the identifier of our block.  The name of the block doesn’t matter, you can name it anything you like but it makes sense to make it relevant to the block.

If we place the block under a default section then it will appear on all pages.  Hope this gets you started!

-Adam

 
Magento Community Magento Community
Magento Community
Magento Community
 
devx
Jr. Member
 
Total Posts:  20
Joined:  2007-08-31
 

Hi Adam,
Thanks man! That was exactly what I was looking to do!

BTW how do i only limit the block to appear only at the frontpage? (there doesnt seem to be a section for the frontpage)

 
Magento Community Magento Community
Magento Community
Magento Community
 
cshontz
Sr. Member
 
Avatar
Total Posts:  85
Joined:  2007-11-07
 
devx - 18 April 2008 09:18 AM

Hi Adam,
Thanks man! That was exactly what I was looking to do!

BTW how do i only limit the block to appear only at the frontpage? (there doesnt seem to be a section for the frontpage)

There’s nothing to it. Go to “CMS -> Manage Pages -> Home Page” in the admin, select “Custom Design” from the left, and add your static block reference code to “Layout Update XML”.

My “Layout Update XML” field currently looks like this:

<reference name="left">
    <
block type="cms/block" name="sample_block" before="-">
        <
action method="setBlockId"><block_id>sample_block</block_id></action>
    </
block>    
</
reference>

Hope that helps! smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
devx
Jr. Member
 
Total Posts:  20
Joined:  2007-08-31
 

thanks man! I am starting to get the hang of it! Time for some well deserved sleep wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
chiaraweb
Guru
 
Avatar
Total Posts:  686
Joined:  2008-03-21
Aviano ~ Italy
 

A Great THANKS to alistek for this explanation!  tongue laugh

easy and fast!!!

 Signature 

Non criticare cio’ che non puoi capire.
Bob Dylan

My Live Magento Shops
http://www.ecobaby.it
http://www.pesicampione.it

 
Magento Community Magento Community
Magento Community
Magento Community
 
randomutterings
Jr. Member
 
Total Posts:  19
Joined:  2008-02-28
 

I have tried adding this code to the home page Layout Update XML field but nothing changes.  I have a static block setup and caching is turned off.

<pre>
<reference name="left">
<block type="cms/block" name="welcome" before="-">
<action method="setBlockId"><block_id>welcome</block_id></action>
</block>
</reference>
</pre>

 
Magento Community Magento Community
Magento Community
Magento Community
 
randomutterings
Jr. Member
 
Total Posts:  19
Joined:  2008-02-28
 

Sorry, the pre tags weren’t supposed to display, not sure of the proper way to post code snippets here.

 
Magento Community Magento Community
Magento Community
Magento Community
 
bbepristis
Jr. Member
 
Total Posts:  25
Joined:  2008-04-28
Muskegon, Michigan
 

Does anyone know if there is a way I can have something display on the top left column on every page without putting the block in every file??

 
Magento Community Magento Community
Magento Community
Magento Community
 
Shamans
Jr. Member
 
Total Posts:  26
Joined:  2008-04-21
 
bbepristis - 10 June 2008 11:05 AM

Does anyone know if there is a way I can have something display on the top left column on every page without putting the block in every file??

You need to modify xml files in…
{magento root dir}/design/frontend/default/default/layout/

(The path may be different depending on whether you’re using a different interface/theme)...But on a default installation, that’s the files you’re using.

Basically, each xml file contributes to the layout of the page (depending on what page you are in).
Start with looking at catalog.xml and page.xml

 
Magento Community Magento Community
Magento Community
Magento Community
 
numberouno
Jr. Member
 
Total Posts:  1
Joined:  2008-07-01
 

Very useful although I noticed something missing. You need to add a reference in whatever layout file you want the static block to appear.

You can call it by it’s name and the getChildHtml command thus:

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

I hope this helps anyone who might be folically challenged as a result of trying to get this to work like me.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 4
 
© Copyright 2009 Varien. Magento, eCommerce software, is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
108677 users|438 users currently online|199753 forum posts