ScubaBen
ScubaBen

Reputation: 138

Get variables always in differnet .phtml templates

I have to use some variables again and again in different files.

$_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;

All this, I need in /templates/catalog/product/view.phtml and /templates/catalog/product/type/grouped.phtml and templates/catalog/product/media.phtml.

Is there a way to gather this in a central file and reuse it in all this places?

Upvotes: 0

Views: 46

Answers (1)

Unex
Unex

Reputation: 1757

Yes, using magento you should be able to create a view helper which can be called from within the view.

You can check This tutorial which should give you everything you need to solve your problem

Upvotes: 1

Related Questions