2011-11-26 27 views
2

我正在尝试做一些看起来应该很简单的事情:在每页的顶部链接上添加一个“主页”链接,除了主页(我正在使用cms页面作为我的主页)。如果可能,我想完全在我的local.xml中完成。如何通过Magento 1.5.1中的local.xml有条件地删除顶级主页链接

我的想法是添加链接默认

<default> 
    <reference name="top.links"> 
     <action method="addLink" translate="label title"> 
      <label>Home</label> 
      <url>/</url> 
      <title>Home</title> 
      <prepare>true</prepare> 
      <urlParams helper="core/url/getHomeUrl"/> 
      <position>1</position> 
      <liParams/> 
      <aParams>class="top-link-home"</aParams> 
      <beforeText></beforeText> 
      <afterText>/</afterText> 
     </action> 
    </reference> 
</default> 

,然后删除它cms_index_index

<cms_index_index> 
    <reference name="top.links"> 
     <action method="removeLinkByUrl"><url helper="core/url/getHomeUrl"/></action> 
    </reference> 
</cms_index_index> 

但这并没有奏效,在主页的链接处处显示出来,包括主页。

我在做什么错?有没有另一种方法可以做到这一点,不涉及黑客攻击?

编辑: 我拼写出整个URL所期望的行为,无论是在我的addLink

<default> 
    <reference name="top.links"> 
     <action method="addLink" translate="label title"> 
      <label>Home</label> 
      <url>http://www.mysite.com/</url> 
      <title>Home</title> 
      <prepare/> 
      <urlParams/> 
      <position>1</position> 
      <liParams/> 
      <aParams>class="top-link-home"</aParams> 
      <beforeText></beforeText> 
      <afterText>/</afterText> 
     </action> 
    </reference> 
</default> 

和我removeLinkByUrl

<cms_index_index> 
    <reference name="top.links"> 
     <action method="removeLinkByUrl"><url>http://www.mysite.com/</url></action> 
    </reference> 
</cms_index_index> 

解决了眼前的问题,但不回答我原来的问题。我想我需要更好地了解Magento如何使用助手呈现网址。

+0

问题来自Magento添加SID参数。它没有被渲染,我不知道为什么它需要在这种情况下。我将在稍后讨论这个问题 – benmarks

回答

1

男人。我需要研究这一点(我喜欢你正在采取的方法),但是如果你对基本URL进行硬编码并且可能追加不安全的SID参数,这应该起作用。

<cms_index_index> 
    <reference name="top.links"> 
     <action method="removeLinkByUrl"><url><![CDATA[http://BASE_URL/?___SID=U]]></url></action> 
    </reference> 
</cms_index_index> 

我不喜欢这个,但它是一个开始。

+0

为什么使用CDATA标签? –

+0

只是出于习惯。 – benmarks

+0

嗨只是想知道你是否在这方面取得了更多的进展,或者如果这应该被视为最终的解决方案。谢谢! –

0

检查,如果你在首页上,然后做你想要什么:

if($this->getIsHomePage()) { 
    echo 'This is Homepage'; 
} else { 
    echo 'This is NOT Homepage'; 

,或者检查标识符名称是网页或不:

$routerName = Mage::app()->getRequest()->getRouteName(); 
$ident = Mage::getSingleton('cms/page')->getIdentifier(); 
if($routerName == 'cms' && $ident == 'home') { 
    echo 'This is Homepage'; 
} else { 
    echo 'This is NOT Homepage'; 
} 
+0

我的意思是,当然,但我的目标是尽可能少地写php,并将我的定制合并到local.xml中......这样可以在维护性路。 –

0

在page.xml将这个:

<block type="page/template_links" name="top.links" as="topLinks"> 
<action method="addLink" translate="label title" name="backhome"> 
     <label>LABEL</label> 
     <url>/</url> 
     <title>Home</title> 
     <prepare/><urlParams/><position>1</position></action>    
</block> 

这个在页面中自定义布局xml

... 
<reference name="top.links"> 
    <action method="removeLinkByUrl"><url>/</url></action> 
</reference> 
... 
+0

请在有关您的代码的答案中更具描述性。请参阅:[如何回答](http://stackoverflow.com/questions/how-to-answer) – askmish

相关问题