Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
{div:class=} h1.
Wiki Markup
Div
classapi-page

fluid.stringTemplate(template,

values)

{section} {column:width=70%} Simple string template system. Takes a template string containing tokens in the form of

Section
Column
width70%

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 Block
:javascript|borderStyle=none|bgColor=white}
javascript
bgColorwhite
borderStylenone
javascript

fluid.stringTemplate(template, values)
{code} *

File

name:

* {{

Fluid.js

}} h2. Parameters {span:class=

Parameters

Span
classborderless-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 | {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}

values

Return Value

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 Block
javascript
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}

Code Block
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}

Code Block
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}