通过local.xml文件更改块的顺序 [英] Change order of blocks via local.xml file

查看:101
本文介绍了通过local.xml文件更改块的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过local.xml文件更改现有块的顺序? 我知道您可以使用after或before属性更改块的顺序,但是如何更改现有块的那些属性.

Is it possible to change the order of already existing blocks via the local.xml file? I know you can change the order of a block with the after or before attribute, but how can one change those attributes of existing blocks.

例如,如果我想将分层导航块放在新闻订阅块的左栏中,我该怎么做?

For example, if I want to place the layered navigation block underneath the newsletter subscription block in the left column, how would I do that?

推荐答案

您需要执行一个小技巧,删除子块并将其添加到新位置:

You need to perform a small trick, remove child block and add it in new position:

<reference name="parent.block.name">
    <action method="unsetChild">
        <alias>child_block_alias</alias>
    </action>
    <action method="insert">
        <blockName>child.block.name</blockName>
        <siblingName>name_of_block</siblingName>
        <after>1</after>
        <alias>child_block_alias</alias>
    </action>
</reference>

此Layout XML指令可以满足您的要求.看一下insert方法的参数简短参考:

This Layout XML instruction does what you want. Look at this short reference of parameters for insert method:

  • blockName是整个布局中的块唯一名称,例如product.view
  • siblingName是块唯一名称,已在插入目标块中存在,用于定位块.留空以将其显示在顶部或底部.
  • after是块位置的布尔标识符.如果等于1,则如果siblingName为空
  • ,则会将该块添加到siblingName之后或子代列表的底部.
  • alias是您的块的别名,如果为空,将使用块的名称.
  • blockName is your block unique name across the layout, product.view for example
  • siblingName is an block unique name, that is already exists in insertion target block, used for positioning of your block. Leave empty to display it at the top or at the bottom.
  • after is a boolean identifier of block position. If equals to 1, then the block will be added after siblingName or in the bottom of the children list if siblingName is empty
  • alias is the alias of your block, if it is empty the name of block will be used.

一些例子:

在最近查看过的产品之后移动购物车侧边栏

<reference name="right">
    <action method="unsetChild">
        <alias>cart_sidebar</alias>
    </action>
    <action method="insert">
        <blockName>cart_sidebar</blockName>
        <siblingName>right.reports.product.viewed</siblingName>
        <after>1</after>
    </action>
</reference>

在最近查看过的产品之前移动购物车侧边栏

<reference name="right">
    <action method="unsetChild">
        <alias>cart_sidebar</alias>
    </action>
    <action method="insert">
        <blockName>cart_sidebar</blockName>
        <siblingName>right.reports.product.viewed</siblingName>
        <after>0</after>
    </action>
</reference>

将购物车侧栏块移动到右侧块的末尾

<reference name="right">
    <action method="unsetChild">
        <alias>cart_sidebar</alias>
    </action>
    <action method="insert">
        <blockName>cart_sidebar</blockName>
        <siblingName></siblingName>
        <after>1</after>
    </action>
</reference> 

将购物车侧栏块移动到左侧块的顶部

<reference name="right">
    <action method="unsetChild">
        <alias>cart_sidebar</alias>
    </action>
</reference>
<reference name="left">
    <action method="insert">
        <blockName>cart_sidebar</blockName>
    </action>
</reference>

享受与Magento的合作!

Enjoy working with Magento!

这篇关于通过local.xml文件更改块的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆