How the block and template work in Magento

I worked with magento for a while, and there are some details that I'm trying to understand how it works, a block and templates, for example, a part that I don’t understand, how you can do it in a template (.phtml file)

$this->getFunctionName(); 

this means that there is a function with this name in the block to which this template has been assigned.
I am trying to write a simple example to see how it works, but I cannot figure it out, so far, I just have a headeach.
How can I use $ this in a .phtml file to call block functions? It seems that .phtml is part of the object, right?

thanks

+4
source share
2 answers

Check the fetchView method Mage_Core_Block_Template, template files are included in this method and have access to the class. Output buffering is used to collect the output of the template, and not to display the template as it is included.

+3
source

When an include / require 'd file exists in PHP, you can assume in most cases that the code is embedded inside the calling file. Consequently, the entire area (including $this inherited by the template file.

+3
source

Source: https://habr.com/ru/post/1341879/


All Articles