Magento – rendering custom form in default theme

layout

I have a custom form which I have made and want to display within the magento default theme (for now, until create specific css for it). To do this I have set out to try and understand magento's layouts, I've read this and this as well as a couple of other pages to try and learn the basics before I dive in, but the articles seems really unhelpful (or am I missing some nuggets of quality information?). So I had a look around at the layout files that come with magento to try and learn from them, the goal being, work out what handles I need to use. IVE FAILED, hence this question.

How do I add my form in to a Magento theme?

indexController.php

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

module/modulename.xml

<handle_form>
    <block type="core/template" name="the_form" output="toHtml" template="ps/prefcentre/signup.phtml" />
</handle_form>

I realise the above will only render the form but how do I create this file to render a default layout around it.

Ive tried so many different options i've lost track of what ive done. From what I have read I first assumed that the default tags held within other .xml files would cause the basic template to load.

I know once I have got this I will be able to learn how to use the layouts, I'm so stuck on this point.

Best Answer

Your controller action should look like this:

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

Let's assume your module is called modulename, your controller IndexController and the action indexAction. In this case your layout file should be:

<?xml version="1.0"?>
<layout>
    <firstmodule_index_layout>
        <reference name="content"><!-- this means you add a block to the content-->
            <block type="core/template" name="the_form" as="the_form" template="ps/prefcentre/signup.phtml" />
        </reference>
    </firstmodule_index_layout>
</layout>

Basically, each action has it's own layout handled built like this: <module_controller_action>