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 }}
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 }}
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.
Source: https://ru.stackoverflow.com/questions/293615/
All Articles