s1lv3r
s1lv3r

Reputation: 264

Magento 1.7 page.xml use block elements multiple times

For layout reasons I needed to have two different header.phtml (header.phtml / header1.phtml). But if I now copy the header block in the page.xml, only the definitions of the latest block seems to work (both of them work independly, but when both blocks are in the page.xml only the latest of both is causing changes).

<block type="page/html_header" name="header" as="header">
    <block type="page/template_links" name="top.links" as="topLinks"/>
    <block type="page/html_wrapper" name="top.bar" as="topBar" translate="label">
        <label>Breadcrumbs</label>
        <action method="setElementClass"><value>top-bar</value></action>
    </block>
</block>

<block type="page/html_header1" name="header1" as="header1">
    <block type="page/template_links" name="top.links" as="topLinks"/>
    <block type="page/html_wrapper" name="top.bar" as="topBar" translate="label">
        <label>Breadcrumbs</label>
        <action method="setElementClass"><value>top-bar</value></action>
    </block>
</block>

Can anybody tell me, where my error is?

Upvotes: 0

Views: 944

Answers (2)

benmarks
benmarks

Reputation: 23205

You are doing too much.

If all you need is to switch the template for the initial block instance, the following will partially suffice:

<action method="setTemplate" block="header"><tpl>page/html/header1.phtml</tpl></action>

I say "partially suffice" because this directive apparently needs to be executed under certain circumstances. Circumstances (such as a particular view or type of view) map to different layout update handles. For example, if you wanted to use a different header template for logged in customers, the complete layout XML would be as follows:

<?xml version="1.0"?>
<layout>
    <customer_logged_in>
         <action method="setTemplate" block="header"><tpl>page/html/header1.phtml</tpl></action>
    </customer_logged_in>
</layout>

Based on the template path specified, you should create the file app/design/frontend/base/default/page/html/header1.phtml, or at least create this file under your custom theme.

Also, you should create a local.xml file in your custom theme's layout folder.

Upvotes: 0

df2k2
df2k2

Reputation: 178

Your problem is in your Block Type for html_header1

Try This:

<block type="page/html_header" name="header1" as="header1" template="page/html/header1.phtml">
    <block type="page/template_links" name="top.links" as="topLinks"/>
        <block type="page/html_wrapper" name="top.bar" as="topBar" translate="label">
        <label>Breadcrumbs</label>
        <action method="setElementClass"><value>top-bar</value></action>
    </block>
</block>

Then copy your page/html/header.phtml to page/html/header1.phtml and make the changes you need to make.

Upvotes: 1

Related Questions