Optionally, additional arguments can be specified using the following syntax:

${var arg1="A value" arg2='A second value'}

The arguments can thus be simple simple strings or quoted strings (single or double quoted). These arguments are applied to a resolved widget in applyArguments() and currently supports only style classes.

The use of XML comments (<!– ... –>) around variables that are bound to widgets will result in bad behaviour since the template parser is ignorant about these comments and the corresponding widgets will believe that they are rendered but aren't actually.

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.

Constructor & Destructor Documentation

The templateText must be proper XHTML, and this is checked unless the XHTML is resolved from a message resource bundle. This behavior is similar to a WText when configured with the Wt::TextFormat::XHTML textformat.

The corresponding variable reference within the template will be replaced with the widget (rendered as XHTML). Since a single widget may be instantiated only once in a template, the variable varName may occur at most once in the template, and the widget must not yet be bound to another variable.

The widget is reparented to the WTemplate, so that it is deleted when the WTemplate is deleted.

If a widget was already bound to the variable, it is deleted first. If previously a string or other value was bound to the variable, it is removed.

You may also pass a nullptrwidget, which will resolve to an empty string.

This method is called when the progressive bootstrap method is used, and support for AJAX has been detected. The default behavior will upgrade the widget's event handling to use AJAX instead of full page reloads, and propagate the call to its children.

You may want to reimplement this method if you want to make changes to widget when AJAX is enabled. You should always call the base implementation.

This is the main method used to resolve variables in the template text, during rendering.

The default implementation considers first whether a string was bound using bindString(). If so, that string is returned. If not, it will attempt to resolve a widget with that variable name using resolveWidget(), and render it as XHTML. If that fails too, handleUnresolvedVariable() is called, passing the initial arguments.

You may want to reimplement this method to provide on-demand loading of strings for your template.

The result stream expects a UTF-8 encoded string value.

Warning

When specializing this class, you need to make sure that you append proper XHTML to the result, without unsafe active contents. The format() methods may be used for this purpose.

The default implementation returns a widget that was bound using bindWidget().

You may want to reimplement this method to create widgets on-demand. All widgets that are returned by this method are reparented to the WTemplate, so they will be deleted when the template is destroyed, but they are not deleted by clear() (unless bind was called on them as in the example below).

This method is typically used for delayed binding of widgets. Usage example:

By default, the internal path encoding (if enabled) is done on the template text before placeholders are being resolved. In some rare situations, you may want to postpone the internal path encoding until after placeholders have been resolved, e.g. if a placeholder was used to provide the string for an anchor href.

The default value is true

void Wt::WTemplate::setInternalPathEncoding

(

bool

enabled

)

Enables internal path anchors in the XHTML template.

Anchors to internal paths are represented differently depending on the session implementation (plain HTML, Ajax or HTML5 history). By enabling this option, anchors which reference an internal path (by referring a URL of the form href="#/..."), are re-encoded to link to the internal path.