firebird
firebird

Reputation: 3521

Backbone.js: Template variable in element attribute doesn't work

I have the following template:

<a href="{{test_url}}>Test</a>

But it doesn't work, instead the {{}} becomes html encoded in the output.

How do I prevent this?

Upvotes: 2

Views: 3705

Answers (1)

Brian Genisio
Brian Genisio

Reputation: 48147

Assuming you are using the default templating engine that comes with Backbone.js (which actually comes from Underscore.js), then the syntax would be:

<a href="<%= test_url %>">Test</a>

Assuming that test_url exists in the data object you are passing to the template. Also, make sure that you are passing a plain old JS object (this.model.toJSON()) to the template function or else the resolution won't happen.

If it turns out you are using a different templating engine, please let us know what engine it is AND provide us with the view code that is rendering the template.

Upvotes: 8

Related Questions