Code Monkey home page Code Monkey logo

Comments (7)

fzerorubigd avatar fzerorubigd commented on August 15, 2024

@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?

from handlebars.php.

JustBlackBird avatar JustBlackBird commented on August 15, 2024

@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.

from handlebars.php.

majortom731 avatar majortom731 commented on August 15, 2024

A workaround would be to store a single backslash in a different variable and then use

{{backslash}}{{var}}

inside the template.

from handlebars.php.

JustBlackBird avatar JustBlackBird commented on August 15, 2024

@majortom731 it's a dirty hack. The problem should be fixed in the Core.

from handlebars.php.

fzerorubigd avatar fzerorubigd commented on August 15, 2024

@majortom731 Actually, I use that in my template right now. but as @JustBlackBird said we need to fix it in core.

from handlebars.php.

JustBlackBird avatar JustBlackBird commented on August 15, 2024

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.

from handlebars.php.

JustBlackBird avatar JustBlackBird commented on August 15, 2024

@fzerorubigd could you please review #118 ?

from handlebars.php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.