Extends
ria.template.Template.
A template that takes a user-defined HTML template string to format
arbitrary objects. A template string is an HTML fragment containing special
placeholders. A placeholder conforms to the pattern @{name}
,
where name
corresponds to the name of a property of the object
to be formatted with this template. Upon formatting, the placeholder will
be replaced with the corresponding property value of the object being
formatted. String, number, or boolean data types are rendered as the
appropriate string value, whilst any other data types, as well as undefined
or null values, are rendered as an empty string. If an empty string is not
desired, then an arbitrary text value can be provided with the following
extended placeholder syntax: @{name:missing value text}
. For
example, the placeholder @{prop1:Value not defined}
will be
replaced with Value not defined
if the object to be formatted
does not contain a property called prop1
, or if its value is
undefined, null, or anything other than a string, number, or boolean.
Method Attributes | Method Name and Description |
---|---|
format(obj)
Formats the given object into an HTML string following the rules
outlined in the class documentation above.
|
For example, if we pass the following template string into the constuctor:
<div class="cityTemplate"> <div> <h3>@{PLACE_NAME}</h3> <div class="location">@{LATITUDE}, @{LONGITUDE}</div> <div style="clear: both;"></div> </div> <div> <span class="label">Country:</span> @{COUNTRY} </div> <hr></hr> </div>
If we then pass the following object into the format method:
{ "COUNTRY": "United Kingdom", "PLACE_NAME": "London", "LATITUDE": 123, "LONGITUDE": 456, }
The following output is returned:
<div class="cityTemplate"> <div> <h3>London</h3> <div class="location">123, 456</div> <div style="clear: both;"></div> </div> <div> <span class="label">Country:</span> United Kingdom </div> <hr></hr> </div>