example:

How to add a class to top links?

I tried adding a class to the top links using for <aParams>class="class-name"</aParams>
example:

<reference name="top.links">
    <action method="addLink" translate="label title" module="customer"><label>My Account</label><url helper="customer/getAccountUrl"/><title>My Account</title><prepare/><aParams>class="top-link-myaccount"</aParams><position>10</position></action>
</reference>

The above trick didn't work for me, at least for version 1.7.0.0.
Any idea?

Edit:
I think I fixed it with <li/><a>class="top-links-register"</a>:

<reference name="top.links">
        <action method="addLink" translate="label title" module="customer"><label>My Account</label><url helper="customer/getAccountUrl"/><title>My Account</title><prepare/><aParams/><position>10</position><li/><a>class="top-link-myaccount"</a></action>
    </reference>

Please note that you must add <li/>

+5
source share
2 answers

As you discovered, the method signature for addLink:

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

Thus, the correct call in the layout, using all the parameters, will be as follows:

<action method="addLink">
    <label/>
    <url/>
    <title/>
    <prepare/>
    <urlParams/>
    <position/>
    <liParams/>
    <aParams/>
    <beforeText/>
    <afterText/>
</action>

Unfortunately, Magento does not use reflection to map children of an action element to named method parameters, and instead depends on the position.

: liParams aParams , , /.

+12

, ( <li>), node ( ) <liParams> :

<action method="addLink">
    <label/>
    <url/>
    <title/>
    <prepare/>
    <urlParams/>
    <position/>
    <liParams>
        <class>myclassname</class>
    </liParams>
    <aParams/>
    <beforeText/>
    <afterText/>
</action>

, , .

<a> , , node:

<action method="addLink">
    <label/>
    <url/>
    <title/>
    <prepare/>
    <urlParams/>
    <position/>
    <liParams/>
    <aParams>
        <class>myclassname</class>
    </aParams>
    <beforeText/>
    <afterText/>
</action>

, , "addLink" node.

Cart Checkout, XML- Top, addLink , , .

. Mage_Checkout_Block_Links base\default\layout\checkout.xml .

+14

All Articles