无法移动Magento中的top.links(topLinks)块

时间:2010-12-15 15:55:46

标签: layout magento

我正在尽我所能按照他们想要的方式编辑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>

alt text

请注意,链接应位于棕色框内(这是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>

alt text

根据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="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>

这带来了最有趣的结果。我可以看到模板被找到但没有出现。

alt text

我真的对此毫无头绪。我在这里做错了吗?对于它的价值,这里是我用于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; ?>

1 个答案:

答案 0 :(得分:2)

我认为,

“删除”规则最后会被处理,因此您必须更改要插入的块的名称。 现在看看如何添加链接:

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文件中。