2

I've created an attribute called hero_text_background in the catalog_category entity. With this i'm looking to update the frontend_model property to render some HTML for the frontend.

To test the frontend model works, i've updated the frontend_model column with the correct class group id in the eav_attribute table for the attribute. And expected to see the return value for the getValue method i've created in the class.

In my themes catalog/category/view.phtml i'm calling the attribute from the category object ($_category->getHeroTextBackground()) this returns the raw attribute value from the database and not through the "frontend model" class.

Do i have to pass my attribute through a method to get the rendered output? Have I configured my attribute wrong?

UPDATE Original install script, for development i've updated the is_html_allowed_on_front and backend_model

$installer = Mage::getResourceModel('catalog/setup', 'default_setup');

$installer->startSetup();

$installer->addAttribute(
    $installer->getEntityTypeId(Mage_Catalog_Model_Category::ENTITY),
    'hero_text_background',
    array(
        'type' => 'varchar',
        'label' => 'Hero Text Background',
        'input' => 'select',
        'source' => 'bennoislost_heroheaders/catalog_category_attribute_source_hero',
        'default' => Bennoislost_HeroHeaders_Model_Catalog_Category_Attribute_Source_Hero::HB_DEFAULT,
        'required' => false,
        'sort_order' => 0,
        'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
        'group' => 'Display Settings',
    )
);

UPDATE 2

The following snippet indeed call's the correct class:

$_heroTextBackground = Mage::getSingleton('eav/config')
    ->getAttribute(Mage_Catalog_Model_Category::ENTITY, 'hero_text_background')
    ->getFrontend()
    ->getValue($_category);

Is there a nicer way to use this in the template file out of the box?

  • My attribute is part of the catalog_category entity not the catalog_product entity – bennoislost Jan 19 '14 at 20:01
  • 1
    Thank you with a little update the following snippit works. $_heroTextBackground = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Category::ENTITY, 'hero_text_background')->getFrontend()->getValue($_category); – bennoislost Jan 19 '14 at 20:22
  • Doesn't make sense, what I wrote. I'll delete it. Glad you found a solution, feel free to post it as answer and mark it. – Fabian Blechschmidt Jan 19 '14 at 20:40
1

The following snippet will load the frontend_model for the attribute:

$_heroTextBackground = Mage::getSingleton('eav/config')
    ->getAttribute(Mage_Catalog_Model_Category::ENTITY, 'hero_text_background')
    ->getFrontend()
    ->getValue($_category);

I'm still wondering if their is a nicer / less verbose way to use this in a category template...

  • sadly I dont see a 'nice' way of doing this, look at getAdditionalData in the Mage_Catalog_Block_Product_View_Attributes that is doing the same thing. – David Manners May 20 '14 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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