I'm creating a popup that loads via ajax default Magento login box.

The default login block template is located in template/persistent/customer/form/login.phtml.

I already have successfully implemented a controller the outputs data for ajax request:


class My_Module_LoginController extends Mage_Core_Controller_Front_Action {  

    public function loginwindowAction() {

        echo 'Hello world'; // I can see this text in ajax response

        // Now, how to print here login block?


What I'm trying to do is just to create block and echo its HTML. Just the block, without the rest of page layout.

Is there any way of doing this without creating page layout xml?


You should be able to do this (block type may not be right so change as needed):

$block = $this->getLayout()->createBlock('customer/form_login')->setTemplate('persistent/customer/form/login.phtml');

  • Thanks, it almost works. Now, I've got fatal error "Call to a member function setTitle() on a non-object in ... /Mage/Customer/Block/Form/Login.php on line 40". Magento login block is trying to setTitle of the head block, which is not defined of course. Is there any way to prevent this, or I'll need to create a custom "login form template"?
    – Marvin3
    Jul 2 '13 at 16:00
  • 2
    Ah the issue is in the _prepareLayout() function so you would need to create a new block and override that function. Alternatively, you could change the block type to 'core/template' and create a new template replacing the block functions e.g. $this->getPostActionUrl() just returns the value for $this->helper('customer')->getLoginPostUrl()
    – Paul
    Jul 2 '13 at 16:11
  • I'd imagine that creating a new block type would be better practice though so I'd do that.
    – Paul
    Jul 2 '13 at 16:12
  • Worked for me..using a custom block though & template
    – BENN1TH
    May 10 '16 at 6:59

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.