|
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
|