Skip to content

Instantly share code, notes, and snippets.

@herveguetin
Last active November 13, 2015 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herveguetin/b87b083c7494cf665eb2 to your computer and use it in GitHub Desktop.
Save herveguetin/b87b083c7494cf665eb2 to your computer and use it in GitHub Desktop.
Using custom XML attributes for <block> nodes in Magento layout files
<?php
// This code must in a block class, child of Mage_Core_Block_Abstract
// Retrieve value of 'alt-template' attribute from layout for current block
$blockElement = $this->getLayout()->getXpath("*/block[@name='" . $this->getNameInLayout() . "']");
if($blockElement) {
/* @var $blockElement Mage_Core_Model_Layout_Element */
$blockElement = end($blockElement);
$altTemplate = $blockElement->getAttribute('alt-template');
if(!is_null($altTemplate)) {
$this->setTemplate($altTemplate); // Or your logic...
}
}
?>
<!-- Example using alt-template attribute -->
<block
type="core/template"
name="my.block"
template="path/to/regular/template.phtml"
alt-template="path/to/alt/template.phtml"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment