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
I'm pretty new at Mustache, so I might just have misunderstood, but it seems quite challenging to deal with user supplied text containing newlines.
I was somewhat surprised to find that Mustache by default performs html encoding/escaping, but not nl2br. I then thought I would simply pass my string as nl2br, but obviously that will result in the s getting escaped themselves. Of course I could use {{{var}}} but then I lose my added security. I then looked into filters but found that $m->addHelper('nl2br', function($value) { return nl2br($value); } ); with {{var | nl2br}} would still result in escaped . Finally I found and adapted #173 and that worked.
Now my main question is whether using $m->addHelper('nl2br', function($text, $mustache) { return nl2br($mustache->render($text)); } ); with {{#nl2br}}{{var}}{{/nl2br}} is indeed the best, cleanest and most correct option.
I was also wondering, whether the answer is that that is the best option or not, if such a case shouldn't be mentioned in the wiki documentation. I looked around quite a bit specifically for this newline situation, since I presumed most mustache.php users would come across it, before moving on to trying to write a filter myself.
The text was updated successfully, but these errors were encountered:
I'm pretty new at Mustache, so I might just have misunderstood, but it seems quite challenging to deal with user supplied text containing newlines.
I was somewhat surprised to find that Mustache by default performs html encoding/escaping, but not nl2br. I then thought I would simply pass my string as nl2br, but obviously that will result in the
s getting escaped themselves. Of course I could use {{{var}}} but then I lose my added security. I then looked into filters but found that
$m->addHelper('nl2br', function($value) { return nl2br($value); } );
with {{var | nl2br}} would still result in escaped. Finally I found and adapted #173 and that worked.
Now my main question is whether using
$m->addHelper('nl2br', function($text, $mustache) { return nl2br($mustache->render($text)); } );
with {{#nl2br}}{{var}}{{/nl2br}} is indeed the best, cleanest and most correct option.I was also wondering, whether the answer is that that is the best option or not, if such a case shouldn't be mentioned in the wiki documentation. I looked around quite a bit specifically for this newline situation, since I presumed most mustache.php users would come across it, before moving on to trying to write a filter myself.
The text was updated successfully, but these errors were encountered: