Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0
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|borderStyle=none|bgColor=white}
fluid.stringTemplate(template, values)
{code}
*File name:* {{Fluid.js

Parameters

}}

h2. Parameters

{span:class=borderless-table
}
|*{{template}}*| (String) a string (can be HTML) that contains tokens embedded into
it
 it |
|*{{values}}*| (Object) a collection of token keys and
values

Return Value

Div
class
Wiki Markup
{div:class=api-page
}

h1. fluid.stringTemplate(template, values)
Section
Column
width70%
javascriptjavascript
bgColorwhite
borderStylenone
Span
class

template

values

Span
classborderless-table

The string with the values inserted.

Column
width5%
Column

See Also

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 Blockjavascriptjavascript
 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}