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

查看:24
本文介绍了通过 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>

此布局 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之后添加block,如果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天全站免登陆