Magento - 您如何在SIDEBAR中检索产品属性?

How would you go about retrieving Product Attributes in the sidebar?

I have edited my Catalog.xml like so:

<default>
<reference name="right">
<block type="core/template" template="callouts/right_template.phtml"/>
</reference>
</default>

and with my product attribute named “sidebar”, i have placed this code inside of the above referenced template file:

<?php echo $_product->getSidebar() ?>

It is pulling the content into the sidebar fine, (tested by using plain text), but the code used to retrieve the attribute is giving me a "Fatal error: Call to a member function getAttributeName() on a non-object”. I’m assuming this is a scoping issue?

(This code worked fine in pulling the attribute when it was inside of “view.phtml")

The callout block doesn't have access to the product object, try changing:

<?php echo $_product->getSidebar() ?>

and use this instead:

<?php 
    $_product = Mage::registry('current_product');
    if($_product){
      echo $_product->getSidebar();
    } 
?>

Notice this will only work in the product page.

Cheers!