php - Magento: Creating a custom block and using in cart.phtml -


i trying create custom magento block can use on cart.phtml. have seen codes $this->getchildhtml('totals'); .

i wonder if create custom block , access this

$this->getchildhtml('myblock'); 

can point me way or references don't find useful resources.

create custom block, simplicity we'll use mage namespace don't need create full module, should creating custom modules too.

app/code/local/mage/checkout/block/myblock.php

class mage_checkout_block_myblock extends mage_core_block_template {     public function test()     {         return 'testing';     } } 

app/design/frontend/default/default/layout/checkout.xml (use templates config files)

<checkout_cart_index translate="label">     <!-- other code in here.. -->     <reference name="content">         <!-- other code here -->         <block type="checkout/cart_totals" name="checkout.cart.totals"                 as="totals" template="checkout/cart/totals.phtml" />          <!-- add block in here.. -->         <block type="checkout/myblock" name="checkout.myblock"                 as="myblock" template="checkout/cart/myblock.phtml" />     </reference> </checkout_cart_index> 

app/design/frontend/default/default/template/checkout/cart/myblock.phtml (or in template custom)

<?php echo $this->test() // shows "testing" ?> 

you can use child block inside cart block require

$this->getchildhtml('myblock'); 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -