Magento – Left/Right Callout open external link in new window

There are “magic” functions in Magento that allow you to literally create functions on the fly that handle the getting / setting of data. I have two callouts in the left column, one which points internally and one that points externally and I wanted only the external link to open in a new window. So, in page.xml layout, I added the following:

<block type="core/template" name="left.permanent.callout.survey" template="callouts/left_col.phtml"><action method="setImgSrc"><src>images/survey-promo-graphic.jpg</src></action><action method="setImgAlt" translate="alt"><alt>$5 off your next order</alt></action><action method="setLinkUrl"><url></url></action><action method="setLinkTarget"><target>_blank</target></action></block>

I added an action element with the method attribute of “setLinkTarget”, and a child element of “target” with the value of “_blank” (for my target attribute of the A tag). In left_col.phtml, I added the “target” element to the “a” element:

<a href="<?php echo $this->getLinkUrl() ?>" <?php if ($this->getLinkTarget()) { echo('target="'.$this->getLinkTarget().'"'); } ?>>

Because of the “magic” functions in Magento, I was able to retrieve the value of “_blank” and insert it into my a element to open the survey in a new window. Hope this helps others!

Another helpful link: Dynamic Left / Right Callout Block by Category AND file_exist

Was this blog post helpful for you?

Support my blog and donate!

My blog is open to the public and will always be freely available. With your donation, we can help others learn, together.