How I can call a module that I created from a phtml ?.
It can be called as a static block, but I have no idea how it can call its own module from a .phtml
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityHow I can call a module that I created from a phtml ?.
It can be called as a static block, but I have no idea how it can call its own module from a .phtml
try this
$this->getLayout()->createBlock('cms/block')->setBlockId('my_static_block_name')->toHtml();
Or
<?php print $this->getLayout()
->createBlock("catalog/product_view")
->setTemplate("catalog/product/view/addto.phtml")
->toHtml(); ?>
or
$this->getLayout()->createBlock(‘core/template’)->setTemplate(‘templateFolder/yourtemplate.phtml’)->toHtml(); ?>
I hope this will help you.
Call static block in your module .phtml bellow way :
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('your_block_identifier')->toHtml(); ?>
For eg. I have created static block in admin side Contact Information
and it is identifier contact_information
then my static block call in my header.phtm file like this way:
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('contact_information')->toHtml(); ?>
Call phtml file in module app/design/frontend/{your_package}/{your_theme}/layout/{your_layout_file}.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<yourmodule_yourcontroller_youraction>
<reference name="content">
<block type="yourmodule/yourblock" name="yourblock" template="yourmodule/yourphtml.phtml" />
</reference>
</yourmodule_yourcontroller_youraction>
</layout>
OR
<?xml version="1.0"?>
<layout version="0.1.0">
<yourmodule_yourcontroller_youraction>
<reference name="content">
<block type="core/text_list" name="yourblock_name" template="yourmodule/yourphtml.phtml" />
</reference>
</yourmodule_yourcontroller_youraction>
</layout>
For eg. My module name : uploadfile
, Controller Name : index
& Action Name : index
,Block name : temp
and phtm file name : temp.phtml
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
</default>
<uploadfile_index_index>
<reference name="content">
<block type="uploadfile/temp" name="temp.file" template="uploadfile/temp.phtml" />
</reference>
</uploadfile_index_index>
</layout>
I have my static block and i print in my static block this:
{{blocktype="holamundo/saludador " name="holamundo_saludador" template="holamundo/holamundo.phtml"}
The id of my static block is saludador.
Well, now in my header.phtml
i call my static block with this:
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('saludador')->toHtml(); ?>
but in the position so i write these, in the browser print this:
{{block type="holamundo/saludador" name="holamundo_saludador" template="holamundo/holamundo.phtml"}
This is my layout.xml:
<?xml version="1.0"?>
<layout version="0.1.0">
<holamundo_index_index>
<reference name="content">
<block type="holamundo/holamundo" name="holamundo" template="holamundo/holamundo.phtml" />
</reference>
</holamundo_index_index>
<holamundo_index_saludar>
<reference name="content">
<block type="holamundo/holamundo" name="holamundo" template="holamundo/holamundo.phtml"/>
</reference>
</holamundo_index_saludar>
</layout>