You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
renderfile currently mutate placeholders, which can leads to unexpected behavior. Instead of that renderFile (and {% set someVar = true %} should create copy).
Example
{# views/a.twig #}
{% setsomeVar='ABC' %}
constTwig=require('twig');constutil=require('util');constrenderFile=util.promisify(Twig.renderFile);construn=async()=>{constplaceholders={};constcontent=awaitrenderFile('./views/a.twig',placeholders);console.log(placeholders);//Placeholders will contain someVar}run().then(a=>console.log(a)).catch(e=>console.error(e));
Now imagine that in views directory there is a list of templates to render. For example:
And run function iterate over all files in views directory.
The expected result of b.twig is empty, however because someVar was created while rendering a.twig and it mutate original placeholders, it will display thisShouldNeverBeTrue.
Of course its easy to create copy of placeholders and use if for each of render.
However it's not obvious that you have to do it, and may safe some debuging hours to find a reason why its behaving like that.
The text was updated successfully, but these errors were encountered:
renderfile
currently mutate placeholders, which can leads to unexpected behavior. Instead of thatrenderFile
(and{% set someVar = true %}
should create copy).Example
Now imagine that in views directory there is a list of templates to render. For example:
And
run
function iterate over all files inviews
directory.The expected result of
b.twig
is empty, however becausesomeVar
was created while renderinga.twig
and it mutate original placeholders, it will displaythisShouldNeverBeTrue
.Of course its easy to create copy of placeholders and use if for each of render.
However it's not obvious that you have to do it, and may safe some debuging hours to find a reason why its behaving like that.
The text was updated successfully, but these errors were encountered: