magento - rendering blocks and child blocks within a theme -


i trying better understanding of how blocks work in magento. have looked @ of files better idea , has helped little, complex limited skills @ moment , still not have proper understanding of going on , how implement them site. realise essential understand working magento thought set list of things try , achieve:

  1. display block (done)

  2. display block , child block

  3. display block within magento layout

  4. position block on page of magento layout

  5. learn commonly used 'type' attributes , when use them

so far have put _index_index namespace/module/etc/config.xml

<frontend>     ....     <layout>         <updates>             <learningblocks>                 <file>namespace/module/childblocks.xml</file>                 <file>namespace/module/blocks.xml</file>             </learningblocks>         </updates>     </layout> </frontend> 

namespace/module/controllers/indexcontroller.php

class namespace_module_indexcontroller     extends mage_core_controller_front_action {     public function indexaction()     {         $this->loadlayout('learningblocks')->renderlayout();     }      public function blocksaction()     {         $this->loadlayout('blocknode')->renderlayout();     } } 

frontend/base/default/layout/namespace/module/blocks.xml

<layout>     <blocknode>         <block type="core/text" name="blocktest" output="tohtml" >             <action method="settext">                 <args>some text display on screen</args>             </action>         </block>     </blocknode> </layout> 

the above worked expected , displayed string 'some text display on screen' on white page. thats i've been able do, cannot child blocks render onto screen , cannot display within theme, let alone try , move within theme

below 1 of attempts cant seem work. why not working?

frontend/base/default/layout/namespace/module/childblocks.xml

<layout>     <abcde>         <block type="core/template" name="childblocks" output="tohtml" template="namespace/module/childblocks.phtml">             <block type="core/text" name="anyname">                 <action method="settext">                     <args>some text add page</args>                 </action>             </block>         </block>     </abcde>      <learningblocks_index_index>         <update handle="abcde" />     </learningblocks_index_index> </layout> 

frontend/base/default/template/namespace/module/childblocks.phtml

<p>from childblock.phtml page</p><?php $this->getchildhtml(); ?> 

nb: have changed namespaces , module names more generic, in hope easier read (they wern't chosen names).

i know not complete answer, may have struggled same problem. have not gone great depth assume if searching answer have read this article , covers all, assume have same issue did i.e. misunderstanding of had learnt tutorial.

on reading answer please aware new magento , there inaccuracies in here, if there sure correct me , edit accordingly.

firstly wrong

public function indexaction() {     $this->loadlayout('learningblocks')->renderlayout(); } 

it should this

public function indexaction() {     $this->loadlayout()->renderlayout(); } 

and have map learningblocks node in layout xml action module_controller_action. doing display block in page within theme.

so render child block

add in layout.xml

<module_controller_action>     <reference name="content">         <block type="module/blockname" name="unique_name" output="tohtml" template="path/toyou/template.phtml" >               <block type="module/blockname" name="another_unique_name" output="tohtml" template="path/toyou/template.phtml" />         </block>     </reference> </module_controller_action>   

then in template file echo out

$this->getchildhtml('another_unique_name') 

if want remove blocks page use remove node such as

<remove name="right"/> <remove name="left"/> 

this page offer list of attributes can used honest found looking through magento files helped more page though


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -