6
votes

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?

4

4 Answers

6
votes

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.

6
votes

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

5
votes

Given the information you provided, I can only give a general solution.

First you need to find the layout XML for this view.phtml. You should be looking for something like:

<block type="..." name="..." ... template="../view.phtml">

To add the declaration of the new template directly under the wrapping block, it should be:

<block type="..." name="..." ... template="../view.phtml">    
    <block type="..." name="phtmlfilename" template="../phtmlfilename.phtml"/>
    ...
</block>

It is also possible to reference the outter block somewhere else:

<reference name="[name_of_view.phtml_block]">
    <block type="..." name="phtmlfilename" template="../phtmlfilename.phtml"/>
</reference>

Type of the new template is the class name, which should be core/template or a subtype of it.

0
votes

The answer to this question is below codes,just change "directory/acc_drop.phtml" to your file path name.

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