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

Can I add a new structural block? 
 
andyg1
Jr. Member
 
Total Posts:  14
Joined:  2008-05-05
England
 

Guys,

Is it possible to add new structural blocks to the page.xml file, e.g.

<block type="page/new_block" name="new_block" as="new" />

or do you have to use all the ones that are currently in the XML, such as

<block type="page/html"…
<block type="page/html_head"…
<block type="page/html_header"…
<block type="page/template_links"…
<block type="page/switch"…
<block type="core/text_list"....

I want to add a new element to every page in the website that will be a container for things like the search, breadcrumbs etc. Is this possible?

Thank you

 
Magento Community Magento Community
Magento Community
Magento Community
 
Pooch
Member
 
Total Posts:  70
Joined:  2008-05-15
Danville, CA USA
 

Ok, this was bugging the heck out of me too… There’s quite a bit of runaround on this subject in the forums… here’s what I’ve found:

1. Yes you can create a new block as you outline above, but it entails editing the core code in app/code/core/Mage/Page/Block/HTML, you would add a new php file named whatever you want your new block to be called there and basically just do a simple __construct and setTemplate there that would reference your template in page/html. The downside of this is that it entails editing the core code so it would be wiped on upgrade… generally a no-no. I saw some stuff that said you could put the same file in either the app/code/community or app/code/local directory, but I couldn’t get that to work, plus I really want to try and stay inside my design directory, so…

2. You can create a basic “container” as is done with the “right, left, and content” blocks by just adding something like

<block type="core/text_list" name="myblock" as="myblock"/>
to page.xml. From there you can populate it with content blocks via the layout files as normal.

Basically think of it this way… create as many plain containers as you like in the page.xml file, in your specific page templates (e.g. page/2columns-left.phtml) wrap the getChildHtml like so:

<div id="myblock"><?php echo $this->getChildHtml('myblock'?></div>
so that you can apply styling to the container, and then create your content blocks via the appropriate layout and make new templates for them there if necessary
<reference name="myblock">
     <
block type="core/template" name="myblock.search" as="myblockSearch" template="catalogsearch/myblock.search.phtml"/>
</
reference>
So in the above example I referenced the new block in the catalogsearch.xml layout and then added a new content block for searching and created a new template for that content block in the catalogsearch directory. Hope that all makes sense.
 
Magento Community Magento Community
Magento Community
Magento Community
 
BarneyHall
Jr. Member
 
Total Posts:  26
Joined:  2009-03-09
 

Thanks for posting this.

I just managed to successfully drop a CMS block into a new (custom) structural block using your second method described above. (I also was keen not to modify any source files).

I have a question though, if anyone has the time… why does this have to be a type “core/text_list”?
You’re quite right above, no other “type” I tried worked. So I was just curious as to whether there was a simple explanation as why only “core/text_list” does?

To me I can’t see why “page/html” wouldn’t work?

Cheers, an answer may just throw some light on my magento progress!

All the best,
Barney

 
Magento Community Magento Community
Magento Community
Magento Community
 
04081982
Jr. Member
 
Total Posts:  1
Joined:  2010-05-18
 

I have been attempting to add a new structural block between the content and the footer blocks and then rendering the subscribe.phtml in the new block,:
my newsletter.xml looks like this:

<reference name="newreference">
<block type="newsletter/subscribe" name="newreference.newsletter" as="newsletter" before="-" template="newsletter/subscribe.phtml"/>
</reference>

my page.xml

<block type="newsletter/subscribe" name="newreference" as="newreference" translate="label" template = “template/newsletter/subscribe.phtml">
<label>New Reference</label>
</block>

subscribe.phtml is untouched

I want to do a 2colums-right.phtml layout, so the related .2columns-right.phtml file as below:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>” lang="<?php echo $this->getLang() ?>">
<head>
<?php echo $this->getChildHtml('head') ?>
</head>
<body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>>
<?php echo $this->getChildHtml('after_body_start') ?>
<div class="wrapper">
<?php echo $this->getChildHtml('global_notices') ?>
<div class="page">
<?php echo $this->getChildHtml('header') ?>
<?php echo $this->getChildHtml('global_messages') ?>
<?php echo $this->getChildHtml('breadcrumbsContainer') ?>
<div class="main col2-right-layout">
<div class="col-main">
<?php echo $this->getChildHtml('content') ?>
<?php echo $this->getChildHtml('newreference') ?>
</div>
<div class="col-right sidebar"><?php echo $this->getChildHtml('right') ?></div>
</div>
<?php echo $this->getChildHtml('footer_before') ?>
<?php echo $this->getChildHtml('footer') ?>
<?php echo $this->getChildHtml('before_body_end') ?>
</div>
</div>
<?php echo $this->getAbsoluteFooter() ?>
</body>
</html>

When I run my code as is,ie with the above code in place I get a blank page,I would appreciate any help

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagePsycho
Mentor
 
Avatar
Total Posts:  1702
Joined:  2009-06-23
 

Inchoos developers are just superbs, they give much valuable things for absolutely free, isn’t that great.
Please look at this:
http://inchoo.net/ecommerce/magento/custom-reference-structural-block/

 
Magento Community Magento Community
Magento Community
Magento Community
 
oe_eduardo
Jr. Member
 
Avatar
Total Posts:  29
Joined:  2011-02-03
London
 

Hi,

base on the incho post I did this post:

please see the folowing tread with the explanation about how to create a new reference and block to move the categories the cms block to the header....

http://www.magentocommerce.com/boards/viewthread/224094/#

saludos,

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