5

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:

<?php
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?

asked Jul 2, 2013 at 15:36

1 Answer 1

12

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');
$this->getResponse()->setBody($block->toHtml());
answered Jul 2, 2013 at 15:45
4
  • 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"? Commented Jul 2, 2013 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() Commented Jul 2, 2013 at 16:11
  • I'd imagine that creating a new block type would be better practice though so I'd do that. Commented Jul 2, 2013 at 16:12
  • Worked for me..using a custom block though & template Commented May 10, 2016 at 6:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.