Can I my current theme call in constructing In custom Magento extension?

  public function _construct(){

     $this->loadLayout();
    $this->renderLayout();

}

public function indexAction(){

    $this->loadLayout();
    $this->renderLayout();

    echo "see My Controller";
}

When I am call layout in index controller the it will display the my cuttent theme. and when I call in _construct then it's display magento default theme. why? can you explain ? how to set my current theme in _construct() function magento extension

Solutions

You need to add

Mage::app()->loadArea($this->getLayout()->getArea());

in your constructor before loading the layout.
That line is needed so magento will know what area to load.
It works in an action because the action is called after preDispatch() is called, and that's where the area is usually loaded.

It doesn't work in the constructor by default because the constructor is called prior to calling preDispatch()

Tags: Extensions

Similar questions

magento theme falling back to default theme even after theme is changed in admin side
magento theme falling back to default theme even after theme is changed in admin side. I am trying to change theme from default to blank theme under default package . I tried clearing all cache and checked System > Configuration > GENERAL > Design > Themes > Layout, it is "blank" and System > Configuration > GENERAL > Design > Package > Current Pac...
Call current product in custom phtml file in Magento 2
On the product page I created a custom module to override the form.phtml file. I also added the option to include a new file called customFile.phtml when the user clicks on a button that is positioned under the product description. In this customFile.phtml file I am trying to retrieve the current product data but it doesn't work. I also injected th...
How can i override the luma theme category page stylings in new custom theme?
We have to override the luma theme stylings of the category page,we have applied pearl theme on top of it.And we are extending same for custom child theme. How can i override the default luma css for it?
How to get the current post being viewed from the aw_blog extension
I have the following code in template/page/html/head.phtml, and for social network sharing I need access to the blogpost content so I can extract the images from the blogposts. but this doens't give me the content of the current blogpost being viewed.
Get current Logged user Wishlist products id in Ajax Call Magento 2.3
I Want currently logged user all wishlist products id's json array via ajax call ?
Magento 2: Custom theme extending Blank Theme and custom module?
First post on here, I've started developing a custom theme extending the blank theme and I'm just curious about making a module. I've started on a module and I've made some blocks & templates, and it all works well, however I'm not sure if I've done everything right. My module is 100% for the custom theme and nothing else, the module is in: And...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.