开发者

Using new Layout Handle globally, defined in Mage_Page, of Magento

开发者 https://www.devze.com 2023-02-05 18:30 出处:网络
Dear Experts, I am mentioning what all I have done so far in one of my projects using Magento version 1.4.2, but PLEASE correct me if any of my process seems wrong. I will be more than grateful to you

Dear Experts,

I am mentioning what all I have done so far in one of my projects using Magento version 1.4.2, but PLEASE correct me if any of my process seems wrong. I will be more than grateful to you all.

I have got some very different look for my product page, so much so that it may not be wise to use the default available page layout handles.

So I thought of using another layout handle "page_product_list" than the available ones (like "page_two_columns_left", "page_two_columns_right"). For using it, I defined a block of XML in the file "config.xml" (located in the folder "/app/code/local/Mage/Page/etc/"), just like the other layout handle blocks. The code for my custom layout handle is:-

<!-- some other nodes -->
<three_columns module="page" translate="label">
  <!-- details of this node -->
</three_columns>
<product_list module="page" translate="label">
  <label>Product List Page</label>
  <template>page/product-list.phtml</template>
  <layout_handle>page_product_list</layout_handle>
</product_list>

So now what I want is to load this layout handle instead of the "page_two_columns_left" & "default" layout handles, whenever any user tries to see the details page of any C开发者_运维知识库ategory.

But it's not working. Can somebody please guide me as to what can be done in order to achieve this properly in Magento way?


Based on the existing layout handles I think in addition to your config.xml changes (which only seem to affect the selection box in admin) you should be doing this:

page.xml

<page_product_list translate="label">
    <label>Product List Page</label>
    <reference name="root">
        <action method="setTemplate"><template>page/product-list.phtml</template></action>
        <!-- Mark root page block that template is applied -->
        <action method="setIsHandle"><applied>1</applied></action>
    </reference>
</page_product_list>

catalog.xml

<catalog_product_view>
    <update handle="page_product_list"/>
    <!-- Existing declarations here -->
</catalog_product_view>


Try this

<product_list module="page" translate="label">
    ....
    <update handle="page_product_list" />
    ....
</product_list>


If I'm following you correctly, you don't need to create any new handles in the layout files, you just need to re-assign the page template to use for the product page. In catalog.xml you'll see the xml that sets the page template for product pages as:

<catalog_product_view translate="label">
    <label>Catalog Product View (Any)</label>
    <!-- Mage_Catalog -->
    <reference name="root">
        <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
    </reference>
...
</catalog_product_view>

In your theme's copy of catalog.xml or in a local.xml file just change the page template to be used on product pages using the existing handle for product pages <catalog_product_view>. Use code like this:

<catalog_product_view>
    <reference name="root">
        <action method="setTemplate"><template>page/product-list.phtml</template></action>
    </reference>
...
</catalog_product_view>

That'll be enough to have Magento pull in your page template instead of one of its default templates. No need to declare your page template additionally in page.xml unless you want it to show up in drop-downs in the Admin Panel as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号