Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers 3

up vote 3 down vote accepted

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>
share|improve this answer
    
could you explain what is the use of liParams and prepare tag –  Meenakshi Sundaram R Jun 17 at 9:25
    
@MeenakshiSundaramR. I added an explanation to the answer. It was too long to fit in a comment. –  Marius Jun 17 at 9:31
    
great explanation..:) –  Meenakshi Sundaram R Jun 17 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> –  Khanh Tran Dinh Jun 17 at 11:33
add comment
<action method="setLinkTarget"><target>_blank</target></action>
share|improve this answer
    
Thank you. I prefer Marius's solution. –  Khanh Tran Dinh Jun 17 at 11:26
add comment

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>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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