Adam Allen Adam Allen - 27 days ago 19
PHP Question

Displaying an attribute in a tab

I have been trying to display a product attribute that i created called “PDF” in a tab. I tried to re-use the code that had been used to get the product description but change it to reference my new Attribute, well so i thought.

This is the code i used:

The attribute code is: pdf
Admin title is: PDF

<?php $_pdf = $this->getProduct()->getPDF(); ?>
<?php if ($_pdf): ?>
<h2><?php echo $this->__('PDF') ?></h2>
<div class="std">
<?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_pdf, 'pdf') ?>
</div>
<?php endif; ?>


I maybe no where near where i have to be but i am new to magento and new to PHP as well.

I dont want to have to use any extensions if possible.

If you can fix this for me you will be a god! thanks in advance for any help.

Answer

You are using $this->getProduct()->getPDF() when you should be using $this->getProduct()->getPdf(). Magento camel cases attribute names for its magic methods.

You could also use $this->getProduct()->getData('pdf').

Comments