【问题标题】:additional parameters in magento's customer.xml layout filemagento 的 customer.xml 布局文件中的附加参数
【发布时间】:2011-09-06 14:14:36
【问题描述】:

我正在尝试通过来自空白主题的 customer.xml 文件(在 Magento 1.4.1.1 中)向顶级客户链接(我的帐户、我的购物车等)添加一些解释性文本

我认为 magento 通过发出 afterText 或 beforeText 参数具有开箱即用的能力,但是当我使用它们时,它似乎只会在链接之前推动东西(而不是之后,这就是我所追求的)。

这是来自 customer.xml 的摘录,其中包括附加的 参数:

<default>
    <!-- Mage_Customer -->
    <reference name="top.links">
      <action method="addLink" translate="label title" module="customer"><label>Your Account</label><url helper="customer/getAccountUrl"/><title>Your Account</title><prepare/><urlParams/><position>10</position><null /><aParams>rel="nofollow"</aParams><afterText>click to login</afterText></action>  
    </reference>
</default>

以前有人遇到过这种情况吗? liParams 是否需要一些额外的参数?

提前致谢!

编辑:这是似乎对我有用的最终代码。请注意按照建议添加的额外字段 谢谢你,它有很大帮助。您和下面的@Zyava 回答都帮助我解决了这个问题。 上面的建议中缺少一个字段(innerText 字段)。我已经把完整的代码放在下面,看起来对我有用。希望它可以帮助别人!

    <action method="addLink" translate="label title" module="customer">
         <label>Your Account</label>
         <url helper="customer/getAccountUrl"/>
         <title>Your Account</title>
         <prepare/>
         <urlParams/>
         <liParams/>
         <aParams>rel="nofollow"</aParams>
         <innerText/>
         <beforeText>yourbeforetext</beforeText>
         <afterText>youraftertext</afterText></action>

非常感谢@clockworkgeek 和@zyava - 你的回答帮助我度过了这个难关。

【问题讨论】:

    标签: magento-1.4 magento


    【解决方案1】:

    不幸的是,XML 标记名称与变量参数无关,重要的是参数的数量。您需要指定直到afterText 的所有参数,包括beforeText

    <action method="addLink" translate="label title" module="customer">
        <label>Your Account</label>
        <url helper="customer/getAccountUrl"/>
        <title>Your Account</title>
        <prepare/>
        <urlParams/>
        <position>10</position>
        <liParams/>
        <aParams>rel="nofollow"</aParams>
        <beforeText/>
        <afterText>click to login</afterText>
    </action>
    

    【讨论】:

    • 感谢clockworkgeek - 这行得通,它只需要添加
    • 这是有原因的吗?这似乎是头上的裤子。
    • 我猜是因为它下面使用了call_user_func_array,它也不匹配变量名,它只关心条目的顺序。否则将意味着额外的努力进行反射,当您可以提供正确数量的参数时,这是不必要的。
    【解决方案2】:

    块“top.links”的类型为Mage_Page_Block_Template_Links。看Mage_Page_Block_Template_Links::addLink()方法:

    public function addLink($label, $url='', $title='', $prepare=false, $urlParams=array(),
        $position=null, $liParams=null, $aParams=null, $beforeText='', $afterText='')
    {
    

    我们可以看到,$afterText 参数在这里存在。现在转到您的主题的page/template/links.phtml,在我的情况下是\app\design\frontend\base\default\template\page\template\links.phtml,并检查那里是否存在&lt;?php echo $_link-&gt;getAfterText() ?&gt; 之类的内容。

    【讨论】:

    • 感谢 zyava - 查看该函数有助于发现一个我不知道的字段 - 现在可以使用。
    猜你喜欢
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-12
    • 2013-02-08
    • 2011-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多