Can you please tell me where the assignment of the $block variable to the template occurs?


I found :

 $tmpBlock = $this->_currentBlock;
 $this->_currentBlock = $block;
 extract($dictionary, EXTR_SKIP);
 include $fileName;
 $this->_currentBlock = $tmpBlock;

But I don’t understand how the $block variable gets into the current symbol table? From where is $block taken in the template?

1 Answer 1


As I can see, the $block was initialized when they call render() function. Example:


$html = $templateEngine->render($this->templateContext, $fileName, $this->_viewVars);

$this->templateContext is the $block that will be used on the template file

This is pure PHP feature, for more clearly, I created a test.php and template.php

  1. test.php

class Block
    public function test()
        echo '1+++';

class Test
    function render($block, $file, $directory)
        include $file;

$block = new Block();

$test = new Test();
$test->render($block, 'template.php', []);
  1. template.php

echo $block->test();
  1. My screen result:

You can see, I can use $block variable on template.php because I initialized it before including


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.