user2409053
user2409053

Reputation: 85

Add custom category attribute to the frontend.

Pages of different category should display different footers and is the idea behind. I know there are lot of similar questions and I tried them all, but they didn't work. I have added custom category attribute to category page, and I want to see it in the footer.

I tried to use:

<?php if($_customAttribute = $this->getCurrentCategory()->getCustomAttribute()):  ?>

<?php echo $_helper->categoryAttribute($_category, $_customAttribute, 'footer_text') ?> 

But I have not got any results for this.

Upvotes: 3

Views: 1143

Answers (1)

Marius
Marius

Reputation: 15206

You can try it like this.

$category = Mage::registry('current_category');
<?php if ($category->getFooterText()) : ?>
    <?php echo Mage::helper('catalog/output')->categoryAttribute($category, $category->getFooterText(), 'footer_text');?>
<?php endif;?>

But keep in mind...if you add this in footer.phtml it won't work with the block cache on. The footer is cached, so once you load a page the code above will have no effect on the next pages.
[EDIT]
If you want to have a different footer on some pages you need to modify the cache key for the footer block. There is an explanation on how to do that in here but it's for a simple page not a category. The concept is the same.
What you need to do is to change only the getCacheKeyInfo method to depend on the category. Something like this:

public function getCacheKeyInfo()
{
    $info = parent::getCacheKeyInfo();
    $category = Mage::registry('current_category');
    if ($category) {
        $info[] = $category->getId();
    }
    return $info;
}

Upvotes: 1

Related Questions