Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento Including a CUSTOM phtml file in view.phtml

Tags:

php

magento

I am trying to work out how to create custom phtml files to include on view.phtml (and ultimately to be called from any default Magento phtml file).

I have created a seperate phtml file with the content I want in it called productbadges.phtml

This will be pulled through as the last item in

I understand the callout usually is

<?php echo $this->getChildHtml('phtmlfilename') ?>

However I know I need to do add something to catalog.xml so Magento recognizes the callout and can source the correct file. But I do not properly understand Magento's XML syntax.

Could anyone assist?

like image 645
user1156108 Avatar asked Jan 18 '12 11:01

user1156108


2 Answers

vicch's response is the correct way of doing it.

However, it's also helpful to know that there is an alternate method:

$block = $this->getLayout()->createBlock(
      'Mage_Core_Block_Template',
      'choose_a_block_name',
       array('template' => 'folder/myphtmlfile.phtml')
 );

I am posting this for general knowledge. This is not the accepted way of doing this, since it is not consistent with how Magento templates and blocks are used.

like image 129
Zachary Schuessler Avatar answered Sep 28 '22 00:09

Zachary Schuessler


you can use

<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('goodtest/test.phtml')->toHtml(); ?>

see also here:

How do i call .phtml block at specfic page in magento?

and

want to call one phtml file in another phtml file using anchor tag

like image 20
eyeonu Avatar answered Sep 28 '22 01:09

eyeonu