Tower
Tower

Reputation: 102785

jQuery template system breaks with curly braces

I am using jQuery templates and they seem to break as soon as I start using curly braces:

${App.t('General', 'Number of users: {users}', { users: 2 })}

It even breaks with a single } within the quotes.

What should I do to avoid this -- is there a way to escape those characters?

Upvotes: 1

Views: 734

Answers (1)

Dave Ward
Dave Ward

Reputation: 60580

It looks like you're trying to mix jQuery Templates and a hand-rolled templating function there. Can you use jQuery Templates for both?

You can use jQuery Templates' {{tmpl}} to render one of its templates inside of another:

<script type="x-jquery-tmpl" id="yourTemplate">
  {{tmpl({users: 2}) "#subTemplate"}}
</script>

<script type="x-jquery-tmpl" id="subTemplate">
  Number of users: ${users}
</script>

Upvotes: 2

Related Questions