Div |
---|
class | Wiki Markup |
---|
{div:class=api-page | }
h1. fluid.stringTemplate(template, values) Section |
---|
Column |
---|
|
|
Simple string template system. Takes a template string containing tokens in the form of
{section}
{column:width=70%}
Simple string template system. Takes a template string containing tokens in the form of "%value". Returns a new string with the tokens replaced by the specified values. Keys and values can be of any data type that can be coerced into a string. Arrays will work here as well.
{code
javascript | javascript | bgColor | white |
---|
borderStyle | none |
---|
:javascript|borderStyle=none|bgColor=white}
fluid.stringTemplate(template, values)
{code}
*File name:* {{Fluid.js
Parameters
Span |
---|
class | }}
h2. Parameters
{span:class=borderless-table
template
| }
|*{{template}}*| (String) a string (can be HTML) that contains tokens embedded into
it values
| it |
|*{{values}}*| (Object) a collection of token keys and
values Return Value
Span |
---|
|
The string with the values inserted. |
|
Column |
---|
|
Examples
In the following example, a data object of key/value pairs is used to produce the string "Paused at: 12 of 14 files (100 Kb of 12000Gb)"
Code Block |
---|
javascript | javascript | values |
{span}
h2. Return Value
{span:class=borderless-table}
|The string with the values inserted.|
{span}
{column}
{column:width=5%}
{column}
{column}
h3. See Also
{column}
{section}
----
h3. Examples
In the following example, a data object of key/value pairs is used to produce the string "Paused at: 12 of 14 files (100 Kb of 12000Gb)"
{code:javascript}
var template = "Paused at: %atFile of %totalFiles files (%atSize of %totalSize)";
var data = {
atFile: 12,
totalFiles: 14,
atSize: "100 Kb",
totalSize: "12000 Gb"
};
var result = fluid.stringTemplate(template, data);
{code}
In the following example, an array of simple values is used to produce the string "Paused at: 12 of 14 files (100 Kb of 12000Gb)"
{code
:javascript
javascript | }
var template = "Paused at: %0 of %1 files (%2 of %3)";
var atFile = "12";
var totalFiles = "14";
var atSize = "100 Kb";
var totalSize = "12000 Gb";
var data = [atFile, totalFiles, atSize, totalSize];
var result = fluid.stringTemplate(template, data);
{code}
In the following example, an array of mixed, complex values is used to produce the string "Paused at: 12 of 14 files (100 Kb of 12000Gb)"
{code
:javascript
javascript | }
var template = "Paused at: %0 of %1 files (%2 of %3)";
var atFile = "12";
var totalFiles = "14";
var atSize = { // This represents a complex object type that has a toString method.
toString: function () {
return "100 Kb";
}
};
var totalSize = "12000 Gb";
var data = [atFile, totalFiles, atSize, totalSize];
var result = fluid.stringTemplate(template, data);
{code}
{div}