2

I have created a custom module Acer_Laptop and trying to display a page when following URL is hit: http://localhost/project/aspire/check/basic

config.xml

<config>
    <modules>
        <Acer_Laptop>
            <version>0.1.0</version>
        </Acer_Laptop>
    </modules>
    <frontend>
    <routers>
           <Acer_Laptop>
                <use>standard</use>
                <args>
                    <module>Acer_Laptop</module>
                    <frontName>aspire</frontName>
               </args>
            </Acer_Laptop>
        </routers>
       <layout>
              <updates>
                  <aspire module="Acer_Laptop">
                      <file>aspire.xml</file>
                  </aspire>
              </updates>
          </layout>  
    </frontend>
</config>

I've created a controller

class Acer_Laptop_CheckController extends Mage_Core_Controller_Front_Action
{
    public function basicAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }
}

a layout file aspire.xml is created as defined:

<?xml version="1.0"?>
<layout>
    <aspire_check_basic>
        <reference name="content">
                <block type="core/template" name="aspire" template="aspire/laptop/check.phtml" />
        </reference>
    </aspire_check_basic>
</layout>

check.phtml template

<h1><?php echo($this->__("Acer Laptop check")); ?></h1>

It only shows header when I go to http://localhost/project/aspire/check/basic. I have tried many tricks to get this work. I want header + the contents of phtml file.

If I change the layout i.e. aspire.xml like below:

<?xml version="1.0"?>
<layout>
    <basic_check>
        <reference name="content">
            <block type="core/template" name="aspire" output="toHtml" template="aspire/laptop/check.phtml"/>
        </reference>
    </basic_check>
</layout>

and in controller instead of $this->loadLayout(); if I use $this->loadLayout('basic_check'); then it shows only the contents of phtml file without the header.

I would really appreciate if someone can help me to fix this.

  • Check the logs for the error but you might want to try echo $this->__('Acer Laptop check')... – zigojacko Jul 16 '15 at 11:22
  • @zigojacko, surprisingly there's no error.. in controller, echo $this->__('Acer Laptop check') works – Raks Jul 16 '15 at 12:52
3

The layout handle is {route}_{controller}_{action}

In your case this is: Acer_Laptop_check_basic, not aspire_check_basic and also not basic_check

Note that aspire is the front name, which only affects the URL:

<routers>
   <Acer_Laptop>                <---- this is the route name !!!
        <use>standard</use>
        <args>
            <module>Acer_Laptop</module>
            <frontName>aspire</frontName>
       </args>
    </Acer_Laptop>
</routers>

You might want to change the route name to aspire for consistency.

  • Thanks a lot for helping me to get closer. If I change the route name to aspire and use <aspire_basic_check>, I can see header + contents. However, since its very old code, I've some restrictions on changes as I'm not sure of all places where it will affect.. so instead of changing the route name to aspire, I have replaced in layout - <aspire_basic_check> by <acer_laptop_check_basic> but surprisingly this too shows header only – Raks Jul 16 '15 at 12:49
  • 1
    The layout handle is case sensitive. – Fabian Schmengler Jul 16 '15 at 12:51
  • thanks for pointing out.. I've changed it to <Acer_Laptop_check_basic> and cleared the cache, but it is still same --> contents of phtml are not shown – Raks Jul 16 '15 at 12:55
  • Moreover, I've also changed the route name back to <Acer_Laptop> – Raks Jul 16 '15 at 13:00
  • if it works with aspire route name, but not with Acer_Laptop, the underscore might be a problem. Never seen that in a route name. – Fabian Schmengler Jul 16 '15 at 13:01

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.