zordius / lightncandy

An extremely fast PHP implementation of handlebars ( http://handlebarsjs.com/ ) and mustache ( http://mustache.github.io/ ),
https://zordius.github.io/HandlebarsCookbook/
MIT License
610 stars 76 forks source link

function_exists validation #242

Open alien315 opened 8 years ago

alien315 commented 8 years ago

If we want to render a single hbs tempalte multiple times in one page, the rendered php code fails because it tries to define multiple times the same function:

function lcr57eed8dde64efifvar($cx, $v, $zero) {

adding a function_exists check is more than enough:

if (!function_exists('lcr57eed8dde64efifvar')) {

zordius commented 8 years ago

You should load your render function for only 1 time ( $renderFunc = require_once('the-compiled-template.php') ) then reuse it many times. ( echo $renderFunc($data1); echo $renderFunc($data2); ....)

You should not include/require the compiled template many times , nor do LightnCandy::prepare($phpString) on the same template many times.

killerpunk commented 7 years ago

Hi Had the same issue , removing the flag FLAG_BESTPERFORMANCE and adding the LightnCandy::FLAG_JSTRUE solved the issue by using the LightCandy runtime instead of dynamic functions . Hope this helps