Reputation: 21
Is it possible in Magento to conditionally add blocks into a layout xml file?
Im thinking along the lines of having an admin config option checkbox - if checked then a block needs to be added to the page and vice versa if not checked.
I could think of a way of doing this via code but not the actualy layout file system itself.
Upvotes: 2
Views: 1730
Reputation: 166066
The ifconfig
paramater can be used to conditionally call an action method
<action method="someBlockMethod" ifconfig="path/to/config"><param1>value</param></action>
The path/to/config
path is passed to Mage::getStoreConfigFlag() to return a boolean.
I'd try using this in combination with the insert
method
<action method="insert" ifconfig="path/to/config"><param>block_name</param></action>
The block with the name or alias of block_name
will need to be already inserted into the layout object by other PHP or XML, so you may need to take additional steps to unset it from its original blocks after inserting it into your new block.
Upvotes: 3
Reputation: 12750
you can try this (i haven't tried it myself):
<action ifconfig='your/extension/active'
Upvotes: 1