2

In ruby we can have several .rhtml files, we can render those files to a html.erb file

Render Partial UI Elements

This is would help us by stop creating multiple UI elements across the pages, rather rendering UI element where ever necessary. I'm looking for similar concept in Php.

Thank you

Community
  • 1
  • 1
Questino
  • 133
  • 1
  • 8

1 Answers1

1

In Magento, the approach is somewhat different. Basically, Magento uses Blocks which are associated with templates in the view, so each page consists of both a block PHP class (they all inherit from Mage_Core_Block_Abstract) and mostly (but there are exceptions) an associated template (phtml file).

To render partials, blocks can have child blocks within them with given child names. From the parent block, you can render the child blocks using getChildHtml($childName). To set variables at the child block, you can use the magic getter and setters, because all block PHP classes ultimately extend from Varien_Object.

mpaepper
  • 3,952
  • 3
  • 21
  • 28
  • Another note: Magento uses the Zend framework which provides exactly the same partial methodology as in Ruby, see for example: http://stackoverflow.com/questions/10487228/view-helper-partial-view-or-something-else However, as mentioned above, Magento takes a somewhat more elaborate view approach, so I think in the context of the framework, you should not use the simple Zend partial view helper. – mpaepper Jan 03 '13 at 10:36