1

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

2
  • Can you provide the code that you used to create the extension? Dec 23, 2015 at 16:44
  • Can you explain some more what you are trying to do?
    – Sander Mangel
    Dec 24, 2015 at 7:08

3 Answers 3

2

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.

1
  • Thank you denish, i solved with: $this->getLayout()->createBlock(‘core/template’)->setTemplate(‘templateFolder/yourtemplate.phtml’)->toHtml(); ?>
    – str_lml
    Dec 24, 2015 at 8:44
2

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>
1

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>

Not the answer you're looking for? Browse other questions tagged or ask your own question.