Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for escaping annotations with “square-brace” / “curly-brace” syntax #3527

Closed
leogr opened this issue Mar 22, 2016 · 2 comments

Comments

@leogr
Copy link

leogr commented Mar 22, 2016

Issue
Assume you need to set the literal value [[WIP]] to an element's property (or an attribute).

Due to the "square-brace" syntax ([[]]), the following code does not work:

<my-element title="[[WIP]]"></my-element>

The reason is that the annotation parser treats [[WIP]] as an annotation for data binding.

Currently, I have not found any documented way to escape the “square-brace” / “curly-brace” syntax. I just found this TODO:

    // TODO(kschaaf): We could modify this to allow an escape mechanism by
    // looking for the escape sequence in each of the matches and converting
    // the part back to a literal type, and then bailing if only literals
    // were found
    _parseBindings: function(text) {

Use cases
Escaping annotation can be very useful when you work with server-side generated HTML, or when you need to pass a JSON serialised string, for example:

<my-element values='{"foo":"{{baz}}"}'></my-element>

Workaround
But I found a working workaround doing so:

<my-element title="[[serialize('[[WIP]]')]]"></my-element>

It works because template has the serialize method that does nothing when the input is a String, as documented here, and so the first passed param is returned untouched.

Questions
I don't think that it's a definitive solution but I would like to know:

  • Is it an acceptable way to escape the annotation syntax?
  • Is there a better way to escape the annotations?
  • Or will it be available in next release?

Currently, I'm just trying to understand which is the best approach for this use case.

I used the [[..]] syntax as example, but it works for {{..}} too
This workaround could also work for googlearchive/TemplateBinding#186

@leogr leogr changed the title Workaround/solution for escaping double-escaped annotations Workaround for escaping annotations with “square-brace” / “curly-brace” syntax Mar 22, 2016
@leogr
Copy link
Author

leogr commented Apr 20, 2016

The #3529 could be a definitive solution

@tjsavage tjsavage added the 1.x label Sep 8, 2016
@TimvdLippe
Copy link
Contributor

@leogr was correct that that PR was intended to implement this. However, we decided to not configure this globally. Rather you can implemented this functionality yourself in _parseBindings. For more info see #3529 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants