2024-02-25 19:17:06 +01:00
<?xml version="1.0" encoding="UTF-8" ?>
<class name= "HTMLTemplate" inherits= "Resource" version= "4.3" >
<brief_description >
2024-02-25 23:37:46 +01:00
A class that can be used to easily script and render HTML with.
2024-02-25 19:17:06 +01:00
</brief_description>
<description >
2024-02-25 23:37:46 +01:00
A class that can be used to easily render HTML with. An instance of this class could be a traditional web application's View.
Some traditional web applications use a templating language to render their final output using a set of variables. Some examples: Blade, Handlebars, Razor, etc. Some of these have features like for loops, ifs, they can even support method calls. Thic class implements similar functinality, albeit in a different manner.
The render control logic should be implemented by overriding [method _render], variable substitotions can be done using the available helper methods.
Note: For a different approach to generating HTML, you can also take a look at [HTMLBuilder].
2024-02-25 19:17:06 +01:00
</description>
<tutorials >
</tutorials>
<methods >
<method name= "_render" qualifiers= "virtual" >
<return type= "void" />
<argument index= "0" name= "request" type= "WebServerRequest" />
<argument index= "1" name= "data" type= "Dictionary" />
<description >
2024-02-25 23:37:46 +01:00
Override this method to implement your own rendering for any given HTMLTemplate.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "add_template" >
<return type= "void" />
<argument index= "0" name= "template" type= "HTMLTemplateData" />
<description >
2024-02-25 23:37:46 +01:00
Adds a [HTMLTemplateData] template.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "clear_template_defaults" >
<return type= "void" />
<description >
2024-02-25 23:37:46 +01:00
Clears template defaults.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "clear_template_overrides" >
<return type= "void" />
<description >
2024-02-25 23:37:46 +01:00
Clears template overrides.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "clear_templates" >
<return type= "void" />
<description >
2024-02-25 23:37:46 +01:00
Clears templates.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "get_and_render_template" >
<return type= "String" />
<argument index= "0" name= "name" type= "StringName" />
2024-02-26 11:36:13 +01:00
<argument index= "1" name= "data" type= "Dictionary" />
2024-02-25 19:17:06 +01:00
<description >
2024-02-26 11:36:13 +01:00
Gets a template string using [method get_template] and does method substitutions on it.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "get_template" >
<return type= "HTMLTemplateData" />
<argument index= "0" name= "index" type= "int" />
<description >
2024-02-25 23:37:46 +01:00
Gets a template.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "get_template_count" qualifiers= "const" >
<return type= "int" />
<description >
2024-02-25 23:37:46 +01:00
Returns the template count.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "get_template_default" qualifiers= "const" >
<return type= "String" />
<argument index= "0" name= "name" type= "StringName" />
<description >
2024-02-25 23:37:46 +01:00
Returns a default template value previously set.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "get_template_override" qualifiers= "const" >
<return type= "String" />
<argument index= "0" name= "name" type= "StringName" />
<description >
2024-02-25 23:37:46 +01:00
Returns an override template value previously set.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "get_template_text" >
<return type= "String" />
<argument index= "0" name= "name" type= "StringName" />
<description >
2024-02-25 23:37:46 +01:00
Returns a template text identified by name. This method first looks into overrides, then it tries to get it from [member templates] (in order), and then it tries default values.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "has_template_default" qualifiers= "const" >
<return type= "bool" />
<argument index= "0" name= "name" type= "StringName" />
<description >
2024-02-25 23:37:46 +01:00
Returns whether a template default denoted by name is set.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "has_template_override" qualifiers= "const" >
<return type= "bool" />
<argument index= "0" name= "name" type= "StringName" />
<description >
2024-02-25 23:37:46 +01:00
Returns whether a template override denoted by name is set.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "remove_template" >
<return type= "void" />
<argument index= "0" name= "index" type= "int" />
<description >
2024-02-25 23:37:46 +01:00
Removes a template.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "remove_template_default" >
<return type= "void" />
<argument index= "0" name= "name" type= "StringName" />
<description >
2024-02-25 23:37:46 +01:00
Removes a template default.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "remove_template_override" >
<return type= "void" />
<argument index= "0" name= "name" type= "StringName" />
<description >
2024-02-25 23:37:46 +01:00
Removes a template override.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "render" >
<return type= "String" />
<argument index= "0" name= "request" type= "WebServerRequest" />
<argument index= "1" name= "data" type= "Dictionary" />
<description >
2024-02-25 23:37:46 +01:00
Use this method to render the final output. This calls [method _render].
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "render_template" >
<return type= "String" />
<argument index= "0" name= "text" type= "String" />
<argument index= "1" name= "request" type= "WebServerRequest" />
<argument index= "2" name= "data" type= "Dictionary" />
<description >
2024-02-25 23:37:46 +01:00
Helper method that does variable substitutions on a given text.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "set_template_default" >
<return type= "void" />
<argument index= "0" name= "name" type= "StringName" />
<argument index= "1" name= "value" type= "String" />
<description >
2024-02-25 23:37:46 +01:00
Sets a template default value.
2024-02-25 19:17:06 +01:00
</description>
</method>
<method name= "set_template_override" >
<return type= "void" />
<argument index= "0" name= "name" type= "StringName" />
<argument index= "1" name= "value" type= "String" />
<description >
2024-02-25 23:37:46 +01:00
Sets a template override value.
2024-02-25 19:17:06 +01:00
</description>
</method>
</methods>
<members >
<member name= "template_defaults" type= "Dictionary" setter= "set_template_defaults" getter= "get_template_defaults" default= "{}" >
2024-02-25 23:37:46 +01:00
Returns all template default values.
2024-02-25 19:17:06 +01:00
</member>
<member name= "template_overrides" type= "Dictionary" setter= "set_template_overrides" getter= "get_template_overrides" default= "{}" >
2024-02-25 23:37:46 +01:00
Returns all template override values.
2024-02-25 19:17:06 +01:00
</member>
<member name= "templates" type= "Array" setter= "set_templates" getter= "get_templates" default= "[ ]" >
2024-02-25 23:37:46 +01:00
Returns all templates.
2024-02-25 19:17:06 +01:00
</member>
</members>
<constants >
</constants>
</class>