Last active
November 13, 2015 19:30
-
-
Save herveguetin/b87b083c7494cf665eb2 to your computer and use it in GitHub Desktop.
Using custom XML attributes for <block> nodes in Magento layout files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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... | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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