Forumlar / Cotonti / Development / Twig: modern template language

Trustmaster
#25931 2010-09-04 13:54
Modulo operator is not a problem, a 2 minute deal ;)

Nested logic blocks is a bit of a problem. The difference between blocks (BEGIN...END) and logic blocks (IF...ELSE..ENDIF) is not just the condition on which they are parsed.

XTemplate2 renders templates from TPL into HTML in 2 runs. On the 1st run it analyzes TPL structure and parses TPL file into serialized PHP objects (stored in datas/cache/templates), so it doesn't need to parse the template on following runs. On the 2nd run it pushes the block tree (unserialized PHP objects) with real-time data into the actual HTML output.

Traditional blocks are structurally parsed on the 1st run and are represented as Xtpl_block objects, because they are pushed by the controller at a run-time. Logical blocks are pulled at run-time by run-time variables, that's why they are not represented in the tree structure generated on 1st run.

If I manage to find a way of parsing them into Xtpl_logic_block objects at "compile-time", then nested blocks within logic will be possible. Then I'd need an expression "compiler" as well. Because logic blocks is the slowest thing in XTemplate2 currently.

Another reason why I was against nested blocks is complexity. Imagine templates full of nested IFs, up to 3 or 5 levels of nesting. Mixed with traditional blocks. Or no traditional blocks at all (in this case it'd be just usual Smarty stuff). If we have nested logic blocks, then the responsibility of keeping the templates neat lies completely on markup coders.

Extensions is quite easy to implement. It actually exists in original XTemplate. I did not implement it for 2.0 because nobody really used this feature till then.

I think these features have been requested quite often for now, so I'll open tickets to implement them all.
May the Source be with you!