Home > Magento > Echo Product Attributes

Echo Product Attributes

Posted on: 5th Mar 2010 By: Adam Moss 2 Comments

A short and simple post from me today, but something that beginner Magento developers might want to know – how to echo individual product attributes on the product view.phtml page. It’s one of those things that you’ll probably want to do at some point, but you don’t know quite where to look.

First create an attribute, which you’d name accordingly. In this example, a pen has attribute ‘pen_colour’.

On app/design/frontend/base/yourtheme/catalog/product/view.phtml add the following code somewhere within the main conditional statement:

<?php echo $_product->getAttributeText('pen_colour') ?>

If you want to echo the same thing on the product listing page, simply add this similar code to the following file: On app/design/frontend/base/yourtheme/catalog/product/list.phtml within each conditional statement:

<?php echo $_product->getResource()->getAttribute('pen_colour')->getFrontend()->getValue($_product) ?>

You also need to ensure that in the attribute settings:

Visible on Product View Page on Front-end is set to ‘Yes’
Used in product listing is set to ‘Yes’

Now you should be able to see attributes echoed onto that pages, separate from the ‘Additional Information’ tab where they normally reside.

2 Responses to “ Echo Product Attributes ”

  1. Display Custom Product Attributes in Magento, Magento Blog and E-Commerce
    #1 | 7th July 2010

    [...] Relatively easy on the surface, and, granted, applicationĀ  this is a question that comes up fairly often – so I thought I’d answer it. This is a topic we’ve covered before with a slightly different method on our Magento Blog at Ecommerce web design, and you can read Adam’s earlier post here. [...]

  2. Fuji
    #2 | 14th November 2010

    Thanks, you are a life saver!

    Works like a charm ;)

Post A Comment

Your comments:
Enclose code snippets within the appropriate tags: [php][/php]   [js][/js]   [xml][/xml]   [css][/css]   [html][/html]
E.g: [php]<?php echo "hello world"; ?>[/php]

Search Blog

Archives

For the record...

Views & opinions in this blog are those of the individual and do not necessarily reflect those of E-commerce Web Design or the Creare Group.