cancel
Showing results for 
Search instead for 
Did you mean: 

Correct way of getting a product/category attribute

Correct way of getting a product/category attribute

Hi there,

 

I've been in and out of Magento development for a while and am finding it hard to find any documentation that will help.


In my base/default/template/catalog/category/view.phtml, the code seems to be slightly... inconsistent.

For example, at the top we declare 

 

$_helper = $this->helper('catalog/output');
$_category = $this->getCurrentCategory();

Yet, further down on line 56, we aren't using the $_category variable
<?php if($_description=$this->getCurrentCategory()->getDescription()): ?>

But, my real question is, with custom attributes, should I be using

$_category->getDescription() or $_helper->categoryAttribute($_category, $_description, 'description') --- how do they differ? Is one better than the other in regards to performance... is it security-related?

Thanks for any help you can offer. Smiley Happy

2 REPLIES 2

Re: Correct way of getting a product/category attribute

@littlepixiez You can get product attribute value by below code.

 

$_product->getData('<your attribute name');

Same as you can get attribute value 

$_category->getData('your attribute name');
-
Magento Programmer | Was my answer helpful? You can accept it as a solution.

Re: Correct way of getting a product/category attribute

I didn't realise you could get it that way. Fantastic! Do you know if there's a "correct" way of doing it? There seems to be a few ways you can get the end result. Smiley Happy

Either way this works great for me so thank you! Cat Happy