I had thought about extending Twig to support EM via extensions.

FYI, EM uses regex to parse large files very efficiently, so having it parse an entire template and just replace expressions within that template will be faster than having Twig parse the template and make dozens of calls to EM.  EM has a fair amount of overhead on startup, so I recommend passing large files to it rather than calling it multiple times per page.

Can you create a wiki page to discuss your work.  That will be easier for us (and others) to track and comment upon than IRC logs and emails.


On Thu, Jan 10, 2013 at 5:43 PM, Sam Mousa <> wrote:
Hey Thomas,

Twig templates are compiled; it is hard, if not impossible, to pass the result of this compilation through EM since Twig compiles to regular PHP.

Instead Twig supports custom functions, this actually allows us to improve templating performance. Instead of EM having to scan the whole template, it will only be called to evaluate the actual expressions.

Since using EM expressions in the templates themselves is not very common I plan to instead implement an EM function inside twig, just as I did for the translations.

This would look as follows:

{that.Q020} would become {{ em('that.Q020') }}, further note that twig supports a lot of logic on its own and therefore the biggest use for EM will be to get the values of variables, which I also intend to expose as twig variables in the future.
These variables would then be available via array or dot notation in twig: {{ em.q1 }} for example, a downside of this approach is that I always have to pass each variable to twig, whereas with the function approach I dont have to do anything new.

I'll be committing some draft stuff to 2.2 branch soonish, please check out some of the code then to get a feel for what I'm doing and how I'm combining the power of Twig with the power of EM!

Hope this clears some things up, if not we can have a more indepth discussion about it whenever you are available =)



On Thu, Jan 10, 2013 at 10:47 PM, Thomas White <> wrote:

Sam, saw your template.  We can easily extend the EM parser to ignore twig delimiters if needed.  Looks like they are {{ }} {% %}
Are there any other curly-brace related delimiters that EM should ignore?