Pretty new to magento and I'm setting up a custom module to override the core newsletter. All I really want to do is add ajax submit to the form, which is straightforward so far, and also allow the form to be both displayed in a lightbox and on the page, depending on the context of the request. i.e within my custom module controller, would I use something like the below when the request is via AJAX, or is there a more recommended way to do this kind of thing? Thanks for any help
$html = Mage::getSingleton('core/layout')->createBlock('core/template') ->setTemplate('my_module/form.phtml')->toHtml(); $this->getResponse()->setBody($html);
EDIT: update after advice from beeplogic. I now get a blank page with the following code. Is there anything obvious I'm doing wrong here?
What I have is a MyCompany_Newsletter_SubscriberController which has a newAction(), overriding core Newsletter controller newAction. My controller action is called fine. I'm trying to target the default
newsletter/subscriber/new In my module config.xml, I have:
<frontend> <routers> <newsletter> <args> <modules> <MyCompany_Newsletter before="Mage_Newsletter">MyCompany_Newsletter</MyCompany_Newsletter> </modules> </args> </newsletter> </routers> <layout> <updates> <newsletter> <file>newsletter.xml</file> </newsletter> </updates> </layout> </frontend>
Then in default/default/layout/newsletter.xml, I have:
<layout> <newsletter_subscriber> <block type="core/text_list" name="content" output="toHtml" as="content"/> </newsletter_subscriber> <newsletter_subscriber_new> <!--NOTE: this will be the generated action layout handle --> <reference name="content"> <block type="core/template" template="newsletter/subscribe.phtml" /> </reference> </newsletter_subscriber_new> </layout>