始终在varynet .phtml模板中获取变量

时间:2015-06-10 11:03:18

标签: php magento

我必须在不同的文件中反复使用一些变量。

$_product = $this->getProduct();
$_helper = $this->helper('catalog/output');
$_productType = $_product->getTypeID();
$_productName = $_helper->productAttribute($_product, $_product->getName(), 'name');
$_manufacturer = $_product->getAttributeText('manufacturer');
$_decor = $_product->getAttributeText('decor');
$_serie = $_product->getAttributeText('serie');
$originalImageWidth = $this->helper('catalog/image')->init($_product, 'image')->getOriginalWidth();
$originalImageHeight = $this->helper('catalog/image')->init($_product, 'image')->getOriginalHeight();
$originalImageRelation = $originalImageWidth / $originalImageHeight;

所有这些,我需要/templates/catalog/product/view.phtml/templates/catalog/product/type/grouped.phtml以及templates/catalog/product/media.phtml

有没有办法在中央文件中收集它并在所有这些地方重复使用?

1 个答案:

答案 0 :(得分:1)

是的,使用magento你应该能够创建一个可以在视图中调用的视图助手。

您可以查看This教程,它可以为您提供解决问题所需的一切