9

I want to display two different CSS

<action method="addItem" ifconfig="module/general/enable">
    <type>js_css</type>
    <name>module/app.css</name>
</action>

In XML we use ifconfig but I want to add two different CSS files like this

if (marketplace/general/enable == 1) {
     css-1
 } else {
     css-2 
 }

How can I do this?

2 Answers 2

16

There is no "inverse directive" to ifconfig. You can still have the name parameter calculated by a helper method like this:

XML:

<action method="addItem">
    <type>js_css</type>
    <name helper="helpername/helpermethod"/>
</action>

helpername is the identifier that you usually pass to Mage::helper($name) and helpermethod the method you want to call.

In your module's helper class (pseudo code):

public function helpermethod()
{
    if ($enabled) {
        return 'module/app1.css';
    } else {
        return 'module/app2.css';
    }
}
1
  • How does it work in magento 2?
    – Black
    Nov 10, 2021 at 15:41
5

use this extension for extended config option

you can use condition tag for tag

<action method="addItem" ifconfig="module/general/enable" condition="1">
    <type>js_css</type>
    <name>module/app.css</name>
</action>
<action method="addItem" ifconfig="module/general/enable" condition="0">
    <type>js_css</type>
    <name>module/app1.css</name>
</action>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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