Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How do I create a simple layout XML file using 2column-right for my modules new controller? 
 
One Step Checkout
Member
 
Avatar
Total Posts:  34
Joined:  2008-03-21
Norway
 

Hello,

I am trying to create a site-wide “Tip A Friend” module which allows the user to tip a friend from any page and not just the product pages. My module is called LadiesRoom_TipAFriend. I have created a controller called IndexController and are able to load it if i enter shop.com/tipafriend/

I now need to be able to show a template which uses the 2column-left.phtml layout and display all the other blocks as normal (you know, shopping cart, newsletter subscription etc).

How do I create a layout XML file, and what lines are necessary to activate this in the controller? I am confused with how I create the XML file and how to map this in the IndexController so it uses the 2column-right layout and renders code from my controller (a block or template?)

If anyone knows any of the core modules I can take a look at to get an idea that would be great.

My modules configuration is as follows:

<?xml version="1.0"?>
<config>
    <
modules>
        <
LadiesRoom_TipAFriend>
            <
version>0.0.1</version>
        </
LadiesRoom_TipAFriend>
    </
modules>
    
    <
frontend>
        <
routers>
            <
tipafriend>
                <use>
standard</use>
                <
args>
                    <
module>LadiesRoom_TipAFriend</module>
                    <
frontName>tipafriend</frontName>
                </
args>
            </
tipafriend>
        </
routers>
    </
frontend>
</
config>

My controllers contents is as follows:

class LadiesRoom_TipAFriend_IndexController extends Mage_Core_Controller_Front_Action
{
    
public function indexAction()
    
{    
        
/* Need code to show my block/template using the 2column-right page layout .. */
    
}
}

I really hope someone can help me with this..

Thanks in advance for any response
Jone

 
Magento Community Magento Community
Magento Community
Magento Community
 
One Step Checkout
Member
 
Avatar
Total Posts:  34
Joined:  2008-03-21
Norway
 

Nobody able to answer me on this one? smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
One Step Checkout
Member
 
Avatar
Total Posts:  34
Joined:  2008-03-21
Norway
 

Bump! :(

 
Magento Community Magento Community
Magento Community
Magento Community
 
nico5
Sr. Member
 
Avatar
Total Posts:  214
Joined:  2008-02-19
France
 

In your IndexController put :

public function indexAction()
    
{    
        $this
->loadLayout();
        
$this->renderLayout();

    
}

Crate the layout, file app/design/frontend/YOUR_THEMES/default/layout/tipafriend.xml :

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
    </default>
    <
tipafriend_index_index>
        <
reference name="content">
            <
block type="tipafriend/tipafriend" name="tipafriend" template="tipafriend/tipafriend.phtml" />
        </
reference>
    </
tipafriend_index_index>
</
layout>

Create a block, file app/code/local/LadiesRoom/TipAFriend/Model/TipAFriend.php

<?php

class LadiesRoom_TipAFriend_Model_TipAFriend extends Mage_Core_Model_Abstract
{
    
public function _construct()
    
{
        parent
::_construct();
        
$this->_init('tipafriend/tipafriend');
    
}
}

Create the template, file app/design/frontend/YOUR_THEME/default/template/tipafriend/tipafriend.phtml

/* What you want to display ... */
 
Magento Community Magento Community
Magento Community
Magento Community
 
One Step Checkout
Member
 
Avatar
Total Posts:  34
Joined:  2008-03-21
Norway
 

Hello,

Thank you very much for your reply. I have tried it now and am getting closer but no success yet. The contents of my .phtml file are not displayed at all, but I get the correct page layout (all the menus and everything else is there, it’s only the content area that’s empty.

You wrote “Create a block” but the file I made is a Model, shouldn’t blocks be in a module’s Block/ folder? And inherit from Mage_Core_Block_Abstract, not Model? Do I need both?

Also, do I need anything in my config.xml to let Magento know of my blocks or something like that? (or the model, if that’s what I want)…

Thanks again for your response, hope you can help me get closer smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
nico5
Sr. Member
 
Avatar
Total Posts:  214
Joined:  2008-02-19
France
 

I’m sorry, you’re right.
You have to create a block, file /app/code/local/LadiesRoom/TipAFriend/Block/TipAFriend.php

<?php

class LadiesRoom_TipAFriend_Block_TipAFriend extends Mage_Core_Block_Template
{

    
public function _prepareLayout()
    
{
        
return parent::_prepareLayout();
    
}

Try that and tell me

 
Magento Community Magento Community
Magento Community
Magento Community
 
One Step Checkout
Member
 
Avatar
Total Posts:  34
Joined:  2008-03-21
Norway
 

Still no luck unfortunately. This is very frustrating.

The current result is here: http://skittent.net/~enoj/tipafriend-magento.png

As you can see the design and layout is correct but the code from my template isn’t displayed at all. my Block/TipAFriend.php contains this:

<?php
class LadiesRoom_TipAFriend_Block_TipAFriend extends Mage_Core_Block_Template
{
    
public function _prepareLayout()
    
{
        
return parent::_prepareLayout();
    
}    
}
?>

My layout/tipafriend.xml contains this:

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
    </default>
    <
tipafriend_index_index>
        <
reference name="content">
            <
block type="tipafriend/tipafriend" name="tipafriend" template="tipafriend/tipafriend.phtml" />
        </
reference>
    </
tipafriend_index_index>
</
layout>

my etc/config.xml file contains this:

<?xml version="1.0"?>
<config>
    <
modules>
        <
LadiesRoom_TipAFriend>
            <
version>0.0.1</version>
        </
LadiesRoom_TipAFriend>
    </
modules>
    
    
    <global>
        <
blocks>
            <
tipafriend>
                <class>
LadiesRoom_TipAFriend_Block</class>
            </
tipafriend>
        </
blocks>
        <
models>
            <
tipafriend>
                <class>
LadiesRoom_TipAFriend_Model</class>
            </
tipafriend>        
        </
models>
    </global>
    
    <
frontend>
        <
routers>
            <
tipafriend>
                <use>
standard</use>
                <
args>
                    <
module>LadiesRoom_TipAFriend</module>
                    <
frontName>tipafriend</frontName>
                </
args>
            </
tipafriend>
        </
routers>
        
        <
layout>
            <
updates>
                <
tipafriend module="LadiesRoom_TipAFriend">
                    <
file>tipafriend.xml</file>
                </
tipafriend>
            </
updates>
          </
layout>        
    </
frontend>
</
config>

Is the model and blocks definitions necessary? Should I remove the model? (I’ve tried this as well, no luck). I have tried putting die() in the Block PHP file so it seems that it is never included at all.

Please let me know if there is any additional information I can provide.. If anyone with some experience could whip up a simple module with my scenario that works that would be awesome. I only need to have a controller and a block that displays a form to tip a friend of the site, and then handle POST data. And it should be in the standard 2column-left.phtml page layout.

 
Magento Community Magento Community
Magento Community
Magento Community
 
quadra
Jr. Member
 
Avatar
Total Posts:  30
Joined:  2008-05-06
 

Ok !
I’ve try on my server and it works !

The block file is not necessary, you can delete file : LadiesRoom\TipAFriend\Block/TipAFriend.php

In the layout file (design\frontend\default\default\layout\tipafriend.xml) write this :

<?xml version="1.0"?>
<layout version="0.1.0">
    <
tipafriend_index_index>
        <
reference name="root">
            <
action method="setTemplate"><template>page/2columns-right.phtml</template></action>
        </
reference>
        
        <
reference name="content">
            <
block type="core/template" name="tipafriend" template="tipafriend/tipafriend.phtml" />
        </
reference>
    </
tipafriend_index_index>
</
layout>

Tell me if it works.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top