3

I am trying to follow http://alanstorm.com/magento_admin_hello_world_revisited tutorial and setup a custom admin module in magento 1.9.x.

The downloadable boilter plate http://alanstorm.com/2013/projects/Pulsestorm_Adminhello.tar works fine. When its uploaded to magento, I can see the following:

enter image description here

When you click the Example menu item, you see a blank page.

So, I want to now load my own .phtml into the view. So, on the module's config.xml I've added the following:

app/code/community/Pulsestorm/Adminhello/etc/config.xml

<?xml version="1.0"?>
<config>
    ...
    <adminhtml>
        <layout>
            <updates>
                <adminhello>
                    <file>adminhello.xml</file>
                </adminhello>
            </updates>
        </layout>
    </adminhtml>
</config>

Then I created the following layout xml file:

app/design/adminhtml/default/default/layout/adminhello.xml

<?xml version="1.0"?>
<layout version="1.0">

    <adminhtml_adminhello_index>
        <block type="core/template" output="toHtml" name="templateBlock" template="adminhello/index.phtml">
    </adminhtml_adminhello_index>

</layout>

Then I created the following template phtml file:

app/design/adminhtml/default/default/template/adminhello/index.phtml

<b>Hello World</b>

When I refresh the page (Pulse Storm -> Example), I still see a blank page. What am I missing here?

4

To show a phtml at layout, you need to add a reference block name <refernece name="Parent_Block_name_At_Layout">

Also, your block is not closed, use / or </block>to close block.

Or you need to set your block name = root instead of templateBlock

Basically...

<?xml version="1.0"?>
<layout version="1.0">

    <adminhtml_adminhello_index>

        <block type="core/template"  name="root" template="adminhello/index.phtml"/>
    </adminhtml_adminhello_index>

</layout>

Or

<?xml version="1.0"?>
<layout version="1.0">
    <adminhtml_adminhello_index>
    <reference name="content">
        <block type="core/template"  name="templateBlock" template="adminhello/index.phtml"/>
    </reference>
    </adminhtml_adminhello_index>
</layout>

If your Magento version is 1.9.2.2 or less and have applied Magento patch supee-6788, you need to change your url process.

If you have adminhtml.xml for this extension, you need to give permission to access the page.

So, go to System > Permissions > Users. select your user and save.

  • Still getting a blank page. – Latheesan Jan 4 '16 at 15:19
  • change core/template to adminhtml/template – Amit Bera Jan 4 '16 at 15:20
  • Sorry, that didn't help either – Latheesan Jan 4 '16 at 15:21
  • did you create adminhtml.xml – Amit Bera Jan 4 '16 at 15:22
  • Why? In the config.xml, I am referencing <file>adminhello.xml</file> so I have created adminhello.xml. – Latheesan Jan 4 '16 at 15:23
1

I think you forgot to put the block in the content reference

<?xml version="1.0"?>
<layout version="1.0">
  <adminhtml_adminhello_index>
    <reference name="content">
      <block type="core/template" name="templateBlock" template="adminhello/index.phtml" />
    </reference>
  </adminhtml_adminhello_index>
</layout>
  • Still getting a blank page. – Latheesan Jan 4 '16 at 15:19
  • Did you clean the layout cache if it id enabled ? Please remove the attribute output="toHtml" to. It is already in output="toHtml" because if it parent content – Matthéo Geoffray Jan 4 '16 at 15:21
0

I will try help you partially, at least up until the point where I am stuck following the same tutorial and than going on to add a phtml file...

First of all, the tar file does not include all the stuff you need to get this working, you will need to read through the rest of his tutorial (or see below).

You should have the following files (and content): app/code/community/Pulsestorm/Adminhello/controllers/AdminhelloController.php

<?php
class Pulsestorm_Adminhello_AdminhelloController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }
}

app/code/community/Pulsestorm/Adminhello/etc/adminhtml.xml

<config>
    <menu>
        <pulsestorm translate="title" module="pulsestorm_adminhello">
            <title>Pulse Storm</title>
            <sort_order>1</sort_order>
            <children>
                <example>
                    <title>Example</title>
                    <sort_order>1</sort_order>
                    <action>adminhtml/adminhello/index</action>
                </example>
            </children>
        </pulsestorm>
    </menu>

    <acl>
        <resources>
            <admin>
                <children>                
                    <pulsestorm translate="title" module="pulsestorm_adminhello">
                        <title>Top Level Pulse Storm Menu Item</title>
                        <sort_order>1</sort_order>
                        <children>
                            <example>
                                <title>Example Menu Item</title>
                            </example>
                        </children>
                    </pulsestorm>
                </children>
            </admin>
        </resources>
    </acl>
</config>

app/code/community/Pulsestorm/Adminhello/etc/config.xml Please note the extra part I added inside adminhtml

<?xml version="1.0"?>
<config>
    <modules>
        <Pulsestorm_Adminhello>
            <version>1.0.0</version>
        </Pulsestorm_Adminhello>
    </modules>
    <adminhtml>
        <layout>
            <updates>
                <pulsestorm_adminhello>
                    <file>pulsestorm_adminhello.xml</file>
                </pulsestorm_adminhello>
            </updates>
        </layout>
    </adminhtml>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <Pulsestorm_Adminhello after="Mage_Adminhtml">Pulsestorm_Adminhello</Pulsestorm_Adminhello>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    <global>
        <helpers>
            <pulsestorm_adminhello>
                <class>Pulsestorm_Adminhello_Helper</class>
            </pulsestorm_adminhello>
        </helpers>
    </global>
</config>

app/code/community/Pulsestorm/Adminhello/Helper/Data.php

<?php
class Pulsestorm_Adminhello_Helper_Data extends Mage_Core_Helper_Abstract
{
}

'app/etc/modules/Pulsestorm_Adminhello.xml'

<?xml version="1.0"?>
<config>
    <modules>
        <Pulsestorm_Adminhello>
            <active>true</active>
            <codePool>community</codePool>
            <depends></depends>
        </Pulsestorm_Adminhello>
    </modules>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <Pulsestorm_Adminhello after="Mage_Adminhtml">Pulsestorm_Adminhello</Pulsestorm_Adminhello>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>

app/design/adminhtml/default/layout/pulsestorm_adminhello.xml

<?xml version="1.0"?>
<layout>
    <adminhtml_adminhello_index>
        <block type="core/template" output="toHtml" name="templateBlock" template="adminhello/hello.phtml" />
    </adminhtml_adminhello_index>
</layout>

As you probably guess from the content above you will also need to create a corresponding phtml file under:

app/design/adminhtml/default/template/adminhello/hello.phtml

So for me, I will attach a screenshot of what I now see.

Hope this helps, and perhaps, someone can help get the phtml file rendering in the middle of the admin area, not down near the closing </body> tag. What I see in my Magento instance (Running 1.9.2.1)

  • If you are having issues, you should post this as a question on its own. Not an answer to similar question maybe. – Latheesan Mar 1 '16 at 9:20
  • Fair point, I kinda thought it might get the original questions like 99% solved. So thought it was worth posting to help them. – johnsnails Mar 1 '16 at 9:23
  • I don't know if you read this page fully but the question is already answered. – Latheesan Mar 1 '16 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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