Good day. I would like to know the principle of writing the conditions in the template engine.

A pattern of this type:

{{ if(1==2) }} {{ else }} {{ endif }} 
  • A template is divided into blocks, conditions are parted, conditions are obtained from them, and one block or another is created or not created from them. Specifically, in a tweek, functional blocks get by tags {%%}, as far as I understand. - etki
  • I would like an approximate code. A better code for finding conditions. As further I understand how. - Essle Jaxcate
  • @Essle can offer to download and watch the same Twig - etki
  • Downloaded, but did not find the necessary code there. - Essle Jaxcate

2 answers 2

At first, any template is parsed into a convenient structure for the template engine.

As a rule, everything is parsed into a tree structure.

{{ if(1==2) }} if content {{ else }} else content {{ endif }}

This piece of code could be parsed something like:

array( 'block_type' => 'ifblock', 'condition' => '1==2', 'content' => 'if content', 'else_content'=> 'else content', )

Well, when passing through the blocks, watch the type, then fulfill the condition, if it is satisfied - display content from content, if not, then from else_content (if there is one, if not, then do nothing)

    You take a template, break it separately into pieces of html code and separately into conditions, etc. Further, every condition is parish, as you like. Usually, the real working code of the language is substituted instead. Then glue pieces of html code and conditions. It should all come together if you do not remove any of the two arrays.