public
Description: PURE Unobtrusive Rendering Engine for HTML
Home | Edit | New

The ruby like #{ ... } notation to mix strings and variables

From the revision 1.7 there is a new shortcut available to concatenate strings. This is only available through directives and not with the auto-rendering based on the class attribute.

We borrowed the #{ … } syntax from Ruby.

We’ll take a similar HTML as our basic Hello World example

<div>
  Hello <span>World</span>

Now we remove the "Hello " string

<div>
  <span>World</span>

Here is the JSON we’ll use to render this HTML.


var json = { "name": "Mary" }

And now the directive that will link them both


var dir = { "span": "Hello #{name}"}

After rendering, the result will be:

<div>
  <span>Hello Mary</span>

The direct assignation, as below, continue to work


var dir = { "span": "name"}

For a working example.
Look at the example 5 in the docs/allExamples.html page from the Download page

Last edited by pure, Thu Jan 29 00:45:15 -0800 2009
Home | Edit | New
Versions: