Magento Includes a custom phtml file in view.phtml

I am trying to develop how to create custom phtml files to be included in view.phtml (and eventually be called from any Magento default phentml file).

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

This will be carried over as the last item in

I understand that a leader usually

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

However, I know that I need to add something to catalog.xml so that Magento recognizes the callout and can fix the correct file. But I do not understand the syntax of Magento XML.

Can anyone help?

+6
source share
4 answers

Responder Response is the right way to do this.

However, it is also useful to know that there is an alternative method:

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

I publish this for general knowledge. This is not an accepted way to do this because it is not consistent with how Magento templates and blocks are used.

+6
source

you can use

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

see also here:

How do I call a .phtml block on a specfic page in magento?

and

want to call one phtml file in another phtml file with an anchor tag

+6
source

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

First you need to find the XML format for this view.phtml. You should look for something like:

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

To add an ad for a new template directly below the wrap box, it must be:

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

You can also specify the removal unit in another place:

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

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

+5
source

The answer to this question is below the 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(); ?> 
0
source

Source: https://habr.com/ru/post/906295/


All Articles