Closed fzerorubigd closed 9 years ago
@JustBlackBird I can't get my head around this. I need to generate exactly one \
before a variable.
handlebars.js use two \\
to output a \
but since its PHP, the the \\
in any case compiled to \
(before loading by engine, I can't understand why PHP translate '\\'
to \
even when I am in single qute!)
So if i want exactly two, I should have \\\
OR \\\\
(WTF?) so this are wrong
https://github.com/XaminProject/handlebars.php/blob/master/tests/Xamin/HandlebarsTest.php#L130
Any idea on this?
@fzerorubigd, according to php manual \\\{
inside of single quotes is equal to \\\\{
, thus this and this test cases do the same job.
To get a single backslash inside a PHP's string one should double it. So
$s = "\\{{var}}";
puts \{{var}}
string into $s
variable and
$s = "\\\\{{var}}";
puts \\{var}
.
The problem is the current Handlebars.php parser does not replace \\
in a template with \
. You can check this behavior by using templates with \Handlebars\Loader\FilesystemLoader
:
\{{var}}
will be rendered to \{{var}}
while
\\{{var}}
becomes \\value
but should be rendered to \value
.
To summarize, you are right, there is no way to render \\{{var}}
template correctly.
A workaround would be to store a single backslash in a different variable and then use
{{backslash}}{{var}}
inside the template.
@majortom731 it's a dirty hack. The problem should be fixed in the Core.
@majortom731 Actually, I use that in my template right now. but as @JustBlackBird said we need to fix it in core.
Here is a jsfiddle that illustrates Handlebars.js behavior: http://jsfiddle.net/cLxyge73/1/ . It seems that only slashes before opening curly brace ({
) should be doubled.
@fzerorubigd could you please review #118 ?
Correct result of (context is
['var' => 'value']
) :is
but handlebars.php produce