【问题标题】:magento show / render one (1) block in two (2) places at the same timemagento 同时在两 (2) 个地方显示/渲染一 (1) 个块
【发布时间】:2015-01-29 19:25:04
【问题描述】:

对不起,这个奇怪的标题,但我花了半天时间试图找到这个,我确信答案已经存在于某个地方,但我找不到它......所以我再次询问其他人有一天可能会找到的可搜索标题。

在响应式 magento 主题中,我希望 topLinks 块同时显示在仅在移动视图中可见的响应式菜单和页脚中。由于这两个地方都由 css 和 page-width 控制,我需要它们同时在模板中呈现。我在 page.xml 中有这个

<block type="page/html_header" name="header" as="header">
    <... lots of other stuff ...>
    <block type="page/template_links" name="top.links" as="topLinks"/>
    <... lots of other stuff ...>
</block>

当我调用&lt;?php echo $this-&gt;getChildHtml('topLinks'); ?&gt; 时,这工作得很好,但是当我输入以下内容时,在 page.xml 中也只有页脚呈现而页眉不呈现。

<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
    <... lots of other stuff ...>
    <block type="page/template_links" name="top.links" as="topLinks"/>
    <... lots of other stuff ...> -->
</block>

我做错了什么,或者我如何克隆第二个位置的一个块的结果?

【问题讨论】:

  • 我相信这是与名称或“as”部分的冲突。尝试更改底部的一个或两个(以及 getChildHtml 中使用的名称。
  • 我试过了...我将 page.xml 中的页脚块更改为 as="topLinksCopy" 并更改了 footer.phtml 中的名称并呈现,但它也停止了页眉渲染。如果您更改 name="top.links",那么您会破坏功能,因为其他模块使用 addLink 操作将实际链接添加到 top.links。
  • 嗨乔恩,看看这里:stackoverflow.com/a/10664584/1512654

标签: php xml magento zend-framework


【解决方案1】:

khartnett,感谢您的回答。解决方案在这里:how to display toplinks at footer in magento?

说清楚,这就是我所做的:

1) 从 page.xml 的页脚块中删除 &lt;block type="page/template_links" name="top.links" as="topLinks"/&gt;

2) 将 &lt;?php echo $this-&gt;getChildHtml('topLinks'); ?&gt; 保留在 footer.phtml 中

3) 在自定义主题中创建一个名为 local.xml 的新布局文件,代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<layout>
    <default>
        <reference name="footer">
            <action method="insert">
                <block_name_to_insert>top.links</block_name_to_insert>
                <sort_relative_to_other_childname/>
                <sort_before_or_after/>
                <alias>topLinks</alias>
            </action>
        </reference>
    </default>
</layout>

【讨论】:

    猜你喜欢
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多