且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Magento边栏自定义

更新时间:2023-11-26 23:28:04

您只需要将产品视图xml更新添加到local.xml布局文件中(或创建它).该文件位于:

You simply need to add the product view xml updates to your local.xml layout file (or create it). The file would be located at:

/app/design/frontend/your_package/your_theme/layout/local.xml

您需要的xml的简化版是:

An abridged version of the xml you would need is:

<?xml version="1.0"?>
<layout version="0.1.0">

<!-- Layout Handle for Product View Page -->
<catalog_product_view>

    <!-- Reference Pointing to Right Sidebar -->
    <reference name="right">

        <!-- Enter All Right Sidebar Layout Updates Here -->

    </reference>

</catalog_product_view>

</layout>

如果您将右侧边栏重命名为其他名称,请将上面的引用名称更改为更改后的名称.以下是一些快速参考资料,显示了您可以通过local.xml进行的操作:


If you renamed your right sidebar something else, change the reference name above to what you changed it to. Here's some quick references to show what you can do to arrange via local.xml:


    <reference name="right">

        <!-- Removes Block By Name -->
        <remove name="name_of_removed_block"/>

        <!-- Insert Moved Block (Must Unset First, See Left Reference) -->
        <action method="insert">
            <blockName>name_of_unset_block</blockName>
            <siblingName>name_of_adjacent_block</siblingName>
            <after>1</after> <!-- 0 = Before / 1 = After Sibling Block -->
        </action>

    </reference>

    <reference name="left">

        <!-- Unset Block By Name, Can Be Inserted Elsewhere As Above -->
        <action method="unsetChild">
            <name>name_of_unset_block</name>
        </action>

    </reference>





    <!-- Blocks Left and Right Automatically Load All Child Html -->
    <reference name="right">

        <!-- Load New Block From Template File -->
        <block type="core/template" name="new_block_name" template="page/html/newblock.phtml" after="adjacent_block_name" />

    </reference>

    <!-- Some Blocks (Like Header) Require Child Html to be Called After Set in XML -->
    <reference name="header">

        <!-- Adding a Block Below Won't Be Enough To Add Our Template File Here -->
        <block type="core/template" name="new_header_block" template="page/html/headerblock.phtml" />

    </reference>


并非所有添加的块都会立即显示,有时您需要进入父块的模板文件以在所需的位置添加子块.在上面的示例中,我使用了"header"块,实际上要添加的任何内容都必须直接编辑.phtml文件. (除非您已将header.phtml更改为仅使用$ this-> getChildHtml('');因为没有块名指示Magento应该加载所有子html块.)


Not all blocks added will show immediately, sometimes you need to go within the parent block's template file to add the child block where you would like. In the above example, I used the "header" block, for anything to actually be added I have to edit the .phtml file directly. (unless you have changed your header.phtml to only use $this->getChildHtml(''); as no block name indicates that Magento should load all child html blocks.)

在这种情况下,我们必须对header.phtml进行更改,然后在该文件中的某个位置(/app/design/frontend/your_package/your_theme/page/html/header.phtml)中添加以下内容:

In this case, we would have to make a change to header.phtml, and somewhere within that file (/app/design/frontend/your_package/your_theme/page/html/header.phtml) you would need to add:

<?php echo $this->getChildHtml('new_header_block'); ?>

您希望在其中看到您的块添加到标题的位置.

那应该使您朝正确的方向开始.确保您的页面/产品/类别在后端的记录中都没有任何自定义布局xml,这也可能会影响前端显示的内容.

Where you would like to see your block added to the header.

That should get you started in the right direction. Make sure that none of your pages/products/categories have any custom layout xml in their records on the backend that may be affecting what shows up on the front as well.