【问题标题】:Can't move top.links (topLinks) block in Magento无法在 Magento 中移动 top.links (topLinks) 块
【发布时间】:2010-12-16 03:38:57
【问题描述】:

我正在尽我最大的努力按照他们希望的方式编辑 Magento 设计(使用 local.xml 而不是编辑 page.xml),但是这个系统非常可怕和复杂,事实证明它非常棘手这样做。

我现在遇到的问题是我似乎无法将“top.links”块移动到标题中的另一个块中。目前在 page.xml 中,此块位于标头块中。我已经尝试了 local.xml 中的所有内容以使其正常工作,我尝试了以下编辑。

从标题中删除 top.links,添加到“Hud”块内。

<layout version="0.1.0">

    <default>
        <!-- Here is where we edit the header block -->
        <reference name="header">
            <remove name="top.links" />
            <remove name="top.search" />
            <!-- This is the block that holds the HUD -->
            <block type="page/html" name="hud" as="hud" template="page/html/hud.phtml">
                <block type="page/template_links" name="top.links" as="topLinks" />
            </block>
        </reference>
    </default>

</layout>

请注意,链接应位于棕色框内(这是 HUD 块)。

不从标题中删除 top.links 块,而是添加到 Hud 块

<layout version="0.1.0">

    <default>
        <!-- Here is where we edit the header block -->
        <reference name="header">
            <remove name="top.search" />
            <!-- This is the block that holds the HUD -->
            <block type="page/html" name="hud" as="hud" template="page/html/hud.phtml">
                <block type="page/template_links" name="top.links" as="topLinks" />
            </block>
        </reference>
    </default>

</layout>

根据 top.links 的代码创建了新的 Links 模板,并在 HUD 的块中引用如下。

<layout version="0.1.0">

    <default>
        <!-- Here is where we edit the header block -->
        <reference name="header">
            <remove name="top.links" />
            <remove name="top.search" />
            <!-- This is the block that holds the HUD -->
            <block type="page/html" name="hud" as="hud" template="page/html/hud.phtml">
                <block type="page/template_links" name="hud.links" as="hudLinks" template="page/template/hudLinks.phtml"/>
            </block>
        </reference>
    </default>

</layout>

下面是hud.phtml

<!-- hud.phtml -->
<div id="hud">
    <h3>Welcome</h3>
    <?php echo $this->getChildHtml('hudLinks') ?>
    <?php echo $this->getChildHtml('top.search') ?> 
</div>

这带来了最有趣的结果。我可以看到找到了模板,但没有出现任何内容。

我真的对此一无所知。我在这里做错了什么吗?值得一提的是,这里是我用于 hudLinks.phtml 和 top.links 模板的代码。

<?php $_links = $this->getLinks(); ?>
<?php if(count($_links)>0): ?>
<ul class="links"<?php if($this->getName()): ?> id="<?php echo $this->getName() ?>"<?php endif;?>>
    <?php foreach($_links as $_link): ?>
        <li<?php if($_link->getIsFirst()||$_link->getIsLast()): ?> class="<?php if($_link->getIsFirst()): ?>first<?php endif; ?><?php if($_link->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?></li>
    <?php endforeach; ?>
</ul>
<?php endif; ?>

【问题讨论】:

  • 如果page.xml 是您自己的主题,我认为编辑没有问题。
  • 我开始的主题基本上使用了Magento基础中的page.xml文件。我尝试在我自己的主题布局文件夹中使用 page.xml 文件来覆盖它,但它似乎不起作用。感谢您的回复。

标签: layout magento


【解决方案1】:

“删除”规则在最后处理,我认为,所以你必须改变你要插入的块的名称。 现在看看如何添加链接:

app/design/frontend/base/default/layout/customer.xml
51:        <reference name="top.links">
52-            <action method="addLink" translate="label title" module="customer"><label>My Account</label><url helper="customer/getAccountUrl"/><title>My Account</title><prepare/><urlParams/><position>10</position></action>
53-        </reference>

链接被添加到名为 top.links 的块中。这就是为什么你的新块是空的。 解决方案:搜索xml文件中是否出现top.links,并将找到的代码添加到local.xml文件中。

【讨论】:

  • 在使用此实例时,我已经从其他 xml 文件中复制并粘贴了完全相同的代码。我将尝试您在上面提供的代码并发表评论。感谢您的回复 greg0ire。
  • @Liam Spencer :在复制和粘贴代码后,确保您调整引用标签的名称属性以匹配您新创建的块的名称。
  • 非常感谢您的帮助。这似乎对我有用,并且可能帮助我更多地了解 Magento 系统。我相信我以后会在这里问更多问题!再次感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-26
  • 2014-02-01
相关资源
最近更新 更多