4

I add new link to top links using

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

It works properly. I want to add target="_blank" to this link. Is there any way to do this?

Thank you.

2
  • where do we need to add this block, im using magento 1.9 default theme
    – Sushivam
    Nov 9, 2016 at 14:55
  • Can we just add this if customer is logged in: <action method="addLink" translate="label title" module="customer"><label>TEST</label><url helper="customer/getLogoutUrl"/><title>TEST</title><prepare/><urlParams/><position>200</position></action> below the Log Out Link
    – Sushivam
    Nov 9, 2016 at 14:58

4 Answers 4

10

The addLink method accepts some extra parameters after position. take a look at Mage_Page_Block_Template_Links::addLink.
So your xml could look like this:

<block type="page/template_links" name="top.links" as="topLinks">
  <action method="addLink" translate="label title">
       <label>Blog</label>
       <url>/blog</url>
       <title>Blog</title>
       <prepare/>
       <urlParams/>
       <position>1</position>
       <liParams />
       <aParams><![CDATA[target="_blank"]]></aParams>
  </action>
</block>

[EDIT]
If prepare is set to true then the url will be generated using

$this->getUrl('value of url tag', array with url params tag)

if it's not set then it will be generated using the url tag as it is.

liParams will be added to the li element that wraps the link.
Something like this:

<li class="some-class>...</li>

Same goes for aParams. They will be added to the <a> element.
In your case that will become

<a target="_blank"...>...</a>
4
  • could you explain what is the use of liParams and prepare tag Jun 17, 2014 at 9:25
  • @MeenakshiSundaramR. I added an explanation to the answer. It was too long to fit in a comment.
    – Marius
    Jun 17, 2014 at 9:31
  • great explanation..:) Jun 17, 2014 at 9:44
  • Thank you. It works. For further informations, if you set aParams, you have to set liParams as well, or at least you must have liParams tag. Otherwise, aParams's value will be taken as liParams. You can also use this for easier reading: <aParams><target>_blank</target></aParams> Jun 17, 2014 at 11:33
2
<action method="setLinkTarget"><target>_blank</target></action>
0
2

Hope this may be helpful to you I am using Magento CE 1.9.0.1 and this works fine for me try to add the link using below XML and you will get what you wants.

<block type="page/template_links" name="top.links" as="topLinks">
  <action method="addLink" translate="label title">
       <label>Blog</label>
       <url>/blog</url>
       <title>Blog</title>
       <prepare/>
       <urlParams/>
       <position>1</position>
       <li/>
       <a>target="_blank"</a>
  </action>
</block>
1

On magento 2.0 this worked for me:

Blog/blog Blog Title 2 target="_blank"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.