【问题标题】:How to conditionally remove top home link via local.xml in Magento 1.5.1如何通过 Magento 1.5.1 中的 local.xml 有条件地删除顶部主页链接
【发布时间】:2011-11-26 14:39:51
【问题描述】:

我正在尝试做一些看起来应该很简单的事情:在每个页面上添加一个“主页”链接到我的 top.links 除了主页(我使用 cms 页面作为我的主页)。如果可能,我想完全在我的 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>

但这并没有奏效,主页链接显示在任何地方,包括主页上。

我做错了什么?还有其他不涉及黑客核心的方法吗?

编辑: 通过在我的 addLink 中拼出整个 url,我得到了所需的行为

<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 如何使用助手呈现 url。

【问题讨论】:

  • 问题来自 Magento 添加 SID 参数。它没有被渲染,我不知道为什么它需要在这种情况下出现。我稍后会研究这个

标签: xml magento magento-1.5


【解决方案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>

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

【讨论】:

  • 您好,只是想知道您是否在这方面取得了更多进展,或者这是否应该被视为最终解决方案。谢谢!
  • 呵呵,没看这个了 :-)
【解决方案2】:

检查你是否在主页然后做你想做的事:

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';
}

【讨论】:

  • 我的意思是,当然,但我的目标是编写尽可能少的 php,并将我的自定义内容整合到一个 local.xml 中...这对以后的可维护性有好处。
【解决方案3】:

把这个放到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>
...

【讨论】:

  • 请在您对代码的回答中更具描述性。参考:How to Answer
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-28
  • 1970-01-01
  • 1970-01-01
  • 2011-05-24
相关资源
最近更新 更多