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

Custom content blocks
 
medlington
Sr. Member
 
Total Posts:  143
Joined:  2008-04-30
 

Hi,

I’m having trouble creating my own custom content blocks.  Bear with me I’ve only just started with magento and am getting a bit confused.

The first thing I have tried to do is to alter a copy of the existing header.phtml so that it only contains the ‘top_links’ block. I copied the file and edited it to just contain:

<div class="header-top-container">
    <
div class="header-top">
        <
div class="quick-access">
            <
strong></strong><br />
            <
div class="shop-access">
                
<?php echo $this->getChildHtml('topLinks'?>
            
</div>
        </
div>
    </
div>
</
div>

Then I saved it as header2.phtml

I then copied ‘header.php’ and changed the following: 

{
        $this
->setTemplate('page/html/header.phtml');
    
}

to:

{
        $this
->setTemplate('page/html/header2.phtml');
    
}

and saved this as ‘header2.php’.

I then called this within my template file and nothing happened. If I call ‘header’ it works fine but not ‘header2’.
Should I be adding this ‘header2’ to an xml file or something?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
medlington
Sr. Member
 
Total Posts:  143
Joined:  2008-04-30
 

Thanks for the info but I’m still a bit confused.

I did what you said and it did apply the ‘header2.phtml’ template to the header but it did this for both ‘header’ and ‘header2’ I couldn’t seem to make them different.

This is the site that I’m trying to recreate in magento:

http://www.quickplaysport.com/index.php

I made it on Joomla but ran into too many problems and couldn’t finish it. I was splitting the header into 2 parts so that the first part would sit in the light grey bar at the top with the account links in and the other header would sit in the div below it with the logo in. I have now altered this part so that it is all one big div which can contain all the header content.
This is what I’ve got so far

http://82.38.173.237/magento/index.php

I have had some joy altering the current content blocks to get what I want but I know this isn’t the best way to do it

What I really need is an idiot’s guide to making a content block such as the ‘header’ from scratch and how to implement this new block within the template. I have read the designers guide but keep getting into a muddle.

Say I wanted to create the top right search box from my site, this is my current understanding of how to do it:

1. I would need to create a new .phtml file within app\design\frontend\default\default\template\page\htmlcalled something like ‘new_search.phtml’ this file would contain the XHTML structure

2. I then add this file into page.xml (is this the correct file?)
like this:

<block type=" core/text_list" name="new_search" as="new_search" template="new_search.phtml" >

(I am also a bit confused about the block type, in the design guide it says not to alter this but if I am making a new content block which one do I start with)

3.Then I think I add it to my skeleton template 3columns.phtml like this:

<?php echo $this->getChildHtml(new_search?>

I don’t seem to be having much joy with this though, there must be something simple that I’m missing or I’m doing it all wrong. Should I be making a new_search.xml file as well?

Sorry if this is something that should be straight forward but I’m really not a programmer and have got into such a mess with several versions of joomla and Oscommerce and have now come to magento all mixed up.

Thanks in advance

 
Magento Community Magento Community
Magento Community
Magento Community
 
medlington
Sr. Member
 
Total Posts:  143
Joined:  2008-04-30
 

ohminu you are an absolute star!

I think Iv got my head around it now and almost finished my site.

I had chosen to duplictae the header more as an exercise than as a key part of making my site. The template from the old site was split into 2 at the top so I thought Id just duplicate the header to create the links in the top and then I would have learned how to create a new block from an old one.

Thanks again

 
Magento Community Magento Community
Magento Community
Magento Community
 
basty
Jr. Member
 
Total Posts:  16
Joined:  2008-08-10
North-Germany
 

@ohminu
Thank you SO MUCH for this great tutorial!!! I missing something like this in the Designer´s Guide. I´ve read it often, but don´t understand it really, how to create or move blocks in the structure. But this is a very good article! Thanks grin

 
Magento Community Magento Community
Magento Community
Magento Community
 
Refugnic
Jr. Member
 
Total Posts:  27
Joined:  2008-07-24
Lichtenfels
 

I must agree, this is a rather comprehensive article. So the xml files...basically it doesn’t matter, WHERE we declare the stuff or as what we declare it. The ‘type’ has no impact on the functionality of the template. Is this correct? Nor does the location, it is only important for the overview. Did I get that right?

 
Magento Community Magento Community
Magento Community
Magento Community
 
malbiniak
Member
 
Avatar
Total Posts:  34
Joined:  2008-07-26
Saint Paul, MN
 

likewise, just want to leave my thanks for ohminu (and other helpful contributors). thanks a ton!

 
Magento Community Magento Community
Magento Community
Magento Community
 
AliciaAO
Jr. Member
 
Total Posts:  20
Joined:  2008-09-25
 

ok wait hold on did i miss something when you said....

“One logic that will help you now is to understand that the ‘header_top’ and the ‘header_bottom’ blocks you’re about to create are located inside a block called ‘header’. That block is assigned via <?php echo $this->getChildHtml('header') ?> in one of the ‘skeleton templates’ which are either 3columns.phtml, 2colmuns-right.phtml, 2 columns-left.phtml...etc depending on which template is bein’g used for your page structure. Just open up page/3columns.phtml and you will see <?php echo $this->getChildHtml('header') ?> somewhere in the template.”

do i need to add <?php echo $this->getChildHtml('header_top') ?> and <?php echo $this->getChildHtml('header_bottom') ?> after <?php echo $this->getChildHtml('header') ?> in each template (3 col, 2 col-right, 2 col-left, one col,and 1 col) ??? or will the ‘header’ tag call the other 2?

little confused here any help would be appreciated.Thank you.

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