Template
Object Hierarchy:
Description:
public class Template : Object
Simple template engine with Mustache/Handlebars-style syntax.
Supports variable substitution, conditionals, loops, filters, and fallback values. Variables use double-brace delimiters. Conditionals
use #if / else / /if directives. Loops use #each / /each directives. Filters are applied with the pipe operator (upper, lower, trim,
escape). Fallback provides a default value when a variable is missing.
Example:
var vars = new HashMap<string, string> (str_hash, str_equal);
vars.put ("name", "World");
string tpl = "Hello, " + "{{na" + "me}}!";
string result = Template.render (tpl, vars);
Content:
Static methods:
- public static CompiledTemplate compile (string template)
Pre-compiles a template for repeated rendering.
- public static string render (string template, HashMap<string,string> vars)
Renders a template string with the given variables.
- public static string? renderFile (Path templatePath, HashMap<string,string> vars)
Reads a template from a file and renders it with the given variables.
- public static string renderJson (string template, JsonValue vars)
Renders a template using a JSON object as variables.
Creation methods:
Inherited Members:
All known members inherited from class GLib.Object
- @get
- @new
- @ref
- @set
- add_toggle_ref
- add_weak_pointer
- bind_property
- connect
- constructed
- disconnect
- dispose
- dup_data
- dup_qdata
- force_floating
- freeze_notify
- get_class
- get_data
- get_property
- get_qdata
- get_type
- getv
- interface_find_property
- interface_install_property
- interface_list_properties
- is_floating
- new_valist
- new_with_properties
- newv
- notify
- notify_property
- ref_count
- ref_sink
- remove_toggle_ref
- remove_weak_pointer
- replace_data
- replace_qdata
- set_data
- set_data_full
- set_property
- set_qdata
- set_qdata_full
- set_valist
- setv
- steal_data
- steal_qdata
- thaw_notify
- unref
- watch_closure
- weak_ref
- weak_unref