Magento – Using custom attributes to display dynamic content.

With Magento’s use of custom attributes,  there is a lot of flexibility. Not only in displaying attributes on the layered navigation or merely outputting them to the additional area of the product page. There is another level of customization possible.  That is, the possibility to display different content based on the vallue of an attribute.

In today’s case,  I am using the manufacturer attribute. While this is not a custom attribute, the same process can be used for any attribute.  What we are going to do is display a message depending on the manufacture’s name.

My first step is to make a static block and put in the content I want to display. This can be anything you want-text or images. My static block is called brand_notify.  Here is the contents of that static block: ‘Dietitian appointment must be indicated as completed in Magento prior to shipment of product.’.

Now that we have our static block, we will need to insert it into the product page, right above the price. I am going to use the app/design/frontend/default/default/template/category/product/view/type/default.phtml. If it doesn’t exist in your theme’s folder, make a copy from the base package, and place in your theme folder.

If you open up the code sample >[download id=”2036″]
you can see that we are using a conditional to identify which manufacturer  to show our static block for, ie: if manufacturer is Advanced Formula, show this static block. Otherwise don’t.

Here is what visitors will see if the product’s manufacturer attribute is Advanced Formula:

Here is what they will see if the manufacturer is not Advanced Formula:

Using this same technique, you could have multiple messages delivered dynamically via static blocks, depending on which value a product attribute has.

So go have some fun with static blocks!

 

 

 

 

This entry was posted in Magento. Bookmark the permalink.