-1

I developed a simple admin panel for my magento theme ( I'm back in Magento ) and wanted to know how I can add a class html via descent in Magento admin . E ' can add it through array ? if so, how can I do ?

4
  • Can you clarify just what you're asking here? May 24, 2015 at 0:03
  • Hi, sorry for my english, i want to add a class in frontend via admin panel. I want to put a drop down menu in admin, where i can select two or more option. If I select option one, magento add class X, if select option 2 , magento add class Y. May 26, 2015 at 17:43
  • Then you can use getConfig() to retrieve options from admin. I'll answer below with an example later May 26, 2015 at 17:44
  • Meant getStoreConfig() above May 26, 2015 at 17:52

1 Answer 1

0

Here is a good tutorial on how to create admin options: http://www.bubblecode.net/en/2012/01/30/add-custom-settings-in-magento-admin-panel/

Once you have created your admin option, you can get the option's value with Mage::getStoreConfig('sectionName/groupName/fieldName');

Then use it to generate your class dynamically, something like:

<?php $class = Mage::getStoreConfig('mySection/myGroup/myField'); ?>
<div class="<?php echo $class; ?>" ></div>

You could get creative and use a PHP ternary operator to set a default class:

<div class="<?php echo ($class=='new-class') ? 'new-class' : 'default-class'; ?>" ></div>

Your Answer

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

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