无法在 Magento 中移动 top.links (topLinks) 块
我正在尽力按照他们希望的方式编辑 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 的代码创建了新的链接模板,并在 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; ?>
I'm trying my very best to edit the Magento design the way they want you to (using a local.xml rather than editing the page.xml) but this system is so horrible and convoluted, it's proving to be seriously tricky to do so.
The problem I have now is that I can't seem to move the "top.links" block into another block in the header. At the moment in page.xml this block is within the header block. I've tried absolutely everything in my local.xml to get this to work, I've tried the following edits.
Remove top.links from header, add inside "Hud" block.
<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>
Note that the links should be inside the brown box (this is the HUD block).
NOT removing the top.links block from header but adding to Hud block
<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>
Created new Links template based on code of top.links, and referred to this in the HUD's block as follows.
<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>
Below is hud.phtml
<!-- hud.phtml -->
<div id="hud">
<h3>Welcome</h3>
<?php echo $this->getChildHtml('hudLinks') ?>
<?php echo $this->getChildHtml('top.search') ?>
</div>
This brings the most interesting results. I can see the template is found but nothing appears.
I really am clueless with this. Am I doing something completely wrong here? For what it's worth, here is the code I'm using for hudLinks.phtml and the top.links template.
<?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; ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为“删除”规则是在最后处理的,因此您必须更改要插入的块的名称。
现在看看如何添加链接:
链接被添加到名为 top.links 的块中。这就是为什么你的新块是空的。
解决方案:搜索 xml 文件中是否出现 top.links ,并将找到的代码添加到 local.xml 文件中。
"remove" rules are processed at the end, I think, so you have to change the name of the block you are inserting.
Now look how a link is added:
The link are added to the block named top.links. That's why your new block is empty.
Solution: search xml files for occurences of top.links , and add the code you find to your local.xml file.