Search code examples
phptemplatesmagentoblock

How block and template work in Magento


i've been working with magento for a while and there is some detail that i'm trying to understand how it works, block and templates, for example, the part i don't understand how works is that you can do this in a template( a .phtml file)

$this->getFunctionName();  

this means that there is a function with that name in the block that was assigned that template.
I'm trying to write a simple example just to see how it works but i can't figure it out, untill now, i just have a headeach.
How is posible that you can use $this within a .phtml file to call the block functions?? Seems to be that the .phtml is part of the object, right?

thanks


Solution

  • Check out the fetchView method of Mage_Core_Block_Template, template files are included within that method and have access to the class. Output buffering is used to collect the template output, rather than displaying the template as it's included.