Layout Can';t在Magento中移动top.links(topLinks)块

Layout Can';t在Magento中移动top.links(topLinks)块,layout,magento,Layout,Magento,我正在尽我最大的努力以他们希望的方式编辑Magento设计(使用local.xml而不是编辑page.xml),但是这个系统非常可怕和复杂,事实证明这样做非常棘手 我现在的问题是,我似乎无法将“top.links”块移动到标题中的另一个块中。目前,在page.xml中,此块位于头块中。我已经尝试了local.xml中的所有内容来实现这一点,我尝试了以下编辑 从标题中删除顶部链接,添加到“Hud”块内部。 <layout version="0.1.0"> <defaul

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

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

从标题中删除顶部链接,添加到“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>
<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块)

不从标题中删除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的代码创建了新的链接模板,并在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>
<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; ?>

id=”“>
class=“first last”>

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

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>
app/design/frontend/base/default/layout/customer.xml
51:        
我的账户我的账户
53-        
链接将添加到名为top.links的块中。这就是为什么你的新街区是空的。
解决方案:搜索xml文件中是否出现top.links,并将找到的代码添加到本地.xml文件。

如果是您自己的主题,则编辑
page.xml
没有问题。我开始使用的主题基本上使用Magento基础中的page.xml文件。我已经尝试过在我自己的主题的布局文件夹中使用page.xml文件来覆盖这个问题,但它似乎不起作用。感谢您的回复。在使用此实例时,我已经从其他xml文件中复制并粘贴了完全相同的代码。我将尝试上面提供的代码,并进行回复。感谢您的回复greg0ire。@利亚姆·斯宾塞:复制和粘贴代码后,请确保调整引用标记的名称属性以匹配新创建块的名称。非常感谢您的帮助。这似乎对我起了作用,也许帮助我更好地理解了Magento系统。我相信将来我会在这里问更多的问题!再次感谢!