What file do I need to edit to add a static block to the homepage?
8 answers
What file do I need to edit to add a static block to the homepage?
Hi Sean:
I’m thinking the following video tutorial may be just what you need . . .
Just as an additional FYI . . . Do be sure to reference our JA MAGENTO TUTORIALS section for tips and tutorials on various Magento related topics.
That doesn’t say how to add it to this templates homepage.
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:
Code:
/** 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 our code in the customer.xml file under the section . . . .
Code:
<!-- 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.
To limit the block to only the home/front page, . . . . 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”.
Hope this gets you started!
Thanks. So if I created a static block and called the block title is "Welcome" and the Identified is "welcome" then what should the code be that I place inside Layout Update XML?
Anyone? Can someone help with specific details?
Perhaps these may provide some additional guidance . . .
Thanks but this still doesn’t tell me which file I need to edit for JM_Asenti’s homepage.
This question is now closed