2015-04-21 165 views
0

我创建了一个包含字符串的自定义属性。现在,我想在我的产品查看页面上显示它,所以我试图编辑view.phtml文件。在产品视图中显示属性

<?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?> 

我试图做类似的事情,因为名称也只是一个属性,但我不知道该怎么做。

谢谢!

回答

1
<?php echo $_product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($_product); ?> 

只需更换 “制造商” 与您的属性代码

这个代码将在工作view.phtml

+0

感谢奏效! –

1

请试试这个。希望这会对你有用。


 
$attribute = $_product->getResource()->getAttribute('CustomAttributeCode'); 
 
if ($attribute) 
 
{ 
 
    echo $attribute_value = $attribute ->getFrontend()->getValue($_product); 
 
}

+0

我把这段代码放到我的view.phtml中,但代码直接写入页面而不是属性的值,我忘记了什么?直到现在,它不被识别为代码。对不起,这些愚蠢的问题,但我是一个初学者:) –

+0

没关系,它解决了 –

相关问题