Hi,
I would like to discuss our current EEL lazy evaluation behavior in templates.
If you create a Fusion Template object and assign a variable with an EEL expression, that expression is put in a Proxy object and lazily evaluated when accessed in the template. The intention was to avoid overhead for not used expressions that are assigned. There is a drawback though, the expression is execute twice if the variable is used twice in the template.
You can easily see the effect if you assign an expression with a math random call to a template:
random = ${Math.random()}
And output the variable twice in the template, you will see two different random values.
Now that could be a desired (side) effect but I rather see it as a bug. First it hurts performance if we execute expressions multiple times, second it’s IMHO unexpected in the template that outputting the same variable can yield different results.
As a result I would be in favour of changing this behaviour and (runtime) cache the result of such an expression in the proxy object when it is first executed.
For reference, this post brought me to the discussion: [SOLVED] Template variable has multiple values