Project

General

Profile

WTemplate functions( ${fun:arg} ) and conditional blocks( ${<cond>} ).

Added by Emir Cem about 13 years ago

Hello,

How can i use WTemplate functions ( ${fun:arg} ) and conditional blocks ( ${} ). Can someone send me a detailed example or explanation?

Thanks for interest.

Regards,

Emir Cem


Replies (1)

RE: WTemplate functions( ${fun:arg} ) and conditional blocks( ${<cond>} ). - Added by Koen Deforche about 13 years ago

Hey,

I've clarified this with some examples in the reference documentation:

B. Functions

${fun:arg} defines a placeholder for applying a function "fun" to an argument "arg".

Optionally, additional arguments can be specified as with a variable placeholder.

Functions are resolved by resolveFunction(), and the default implementation considers functions bound with addFunction(). There are currently two functions that are generally useful:

  • Functions::tr() : resolves a localized strings, this is convenient to create a language neutral template, which contains translated strings
  • Functions::id() : resolves the id of a bound widget, this is convenient to bind elements to a form widget using its for attribute.

For example, the following template uses the "tr" function to translate the age-label using the "age-label" internationalized key.

WTemplate *t = new WTemplate();

t->addFunction("tr", &WTemplate::Functions::tr);

t->setTemplateText(\"

${tr:age-label} ${age-input}

");

t->bindWidget("age-input\", ageEdit_ = new WLineEdit());

C. Conditional blocks

${} starts a conditional block with a condition name "cond", and must be closed by a balanced ${}.

For example:

WTemplate *t = new WTemplate();

t->setTemplateText(\"

${} Register ... ${}

");

t->setCondition("if-register\", true);

Conditions are set using setCondition().

(due to a redmine bug, you need to replace < by < and > by > in the source code above ...

Regards,

koen

    (1-1/1)