Template parser compiled template format change

0 views
Skip to first unread message

Alexander Obuhovich

unread,
Jan 8, 2013, 4:41:20 AM1/8/13
to Development In-Portal
I've recently looked at how Twig stores it's compiled templates and I liked it. It simply creates unique class name and wraps all template contents into it.

Usual template consists of 2 things (both optional):
  • element definitions - creates a function that can be used later, but doesn't produce any output at place, where it's defined
  • tags that output something

Because right now we don't use class to wrap functions we create some crazy hashes based on template_path+element_location+element_name.

When wrapped in a class we can improve several things:
  1. only 1 weird hash per file (in class name)
  2. functions, created as a result of template compilation not accessible in global scope (no need to exclude whole /system/cache folder, just to make auto-complete more intelligent)
  3. methods in compiled templates match exact element names in that template, so searching for a compiled method representation is easy (if you need to debug it or something)
  4. mapping between block names and their implementation points are easier to understand (e.g. if you have an element with same name locally in some template, then you'll see in which one exactly) 

Reply all
Reply to author
Forward
0 new messages