Wt  4.10.4
Static Public Member Functions | List of all members
Wt::WTemplate::Functions Struct Reference

A collection of predefined functions. More...

#include <WTemplate.h>

Static Public Member Functions

static bool tr (WTemplate *t, const std::vector< WString > &args, std::ostream &result)
 A function that resolves to a localized string. More...
 
static bool block (WTemplate *t, const std::vector< WString > &args, std::ostream &result)
 A function that renders a macro block. More...
 
static bool while_f (WTemplate *t, const std::vector< WString > &args, std::ostream &result)
 A function that renders a macro block as long as the given condition is true. More...
 
static bool id (WTemplate *t, const std::vector< WString > &args, std::ostream &result)
 A function that resolves the id of a bound widget. More...
 

Detailed Description

A collection of predefined functions.

See also
addFunction()

Member Function Documentation

◆ block()

bool Wt::WTemplate::Functions::block ( WTemplate t,
const std::vector< WString > &  args,
std::ostream &  result 
)
static

A function that renders a macro block.

The function will consider the first argument as the key for a localized string that is a macro block, and additional arguments as positional parameters in that block.

For example, a template that contains:

...
${block:form-field category}
...
void field(Action &action, V &value, const std::string &name, int size=-1)
Maps a database object field.
static bool block(WTemplate *t, const std::vector< WString > &args, std::ostream &result)
A function that renders a macro block.
Definition: WTemplate.C:94

would look-up the following message:

<message id="form-field">
<div class="control-group">
${{1}-info}
</div>
</message>

and render as:

...
<div class="control-group">
${category-info}
</div>
...

◆ id()

bool Wt::WTemplate::Functions::id ( WTemplate t,
const std::vector< WString > &  args,
std::ostream &  result 
)
static

A function that resolves the id of a bound widget.

For example, when bound to the function "id", template text that contains a place-holder

... ${id:name} ...
static bool id(WTemplate *t, const std::vector< WString > &args, std::ostream &result)
A function that resolves the id of a bound widget.
Definition: WTemplate.C:106

will be resolved to the value of:

t->resolveWidget("name")->id()

This is useful for binding labels to input elements.

See also
addFunction()

◆ tr()

bool Wt::WTemplate::Functions::tr ( WTemplate t,
const std::vector< WString > &  args,
std::ostream &  result 
)
static

A function that resolves to a localized string.

For example, when bound to the function "tr", template that contains the placeholder

... ${tr:name} ...
static bool tr(WTemplate *t, const std::vector< WString > &args, std::ostream &result)
A function that resolves to a localized string.
Definition: WTemplate.C:88

will be resolved to the value of:

WString::tr("name")
static WString tr(const char *key)
Creates a localized string from a key.
Definition: WString.C:383
See also
addFunction()

◆ while_f()

bool Wt::WTemplate::Functions::while_f ( WTemplate t,
const std::vector< WString > &  args,
std::ostream &  result 
)
static

A function that renders a macro block as long as the given condition is true.

The function will consider the first argument as the condition, and the second argument as the key for a localized string that is a macro block.

Just like the block() function, you can provide additional arguments, so the third argument will be what is filled in into {1} in the macro block, etc.