arsd.webtemplate

This provides a kind of web template support, built on top of arsd.dom and arsd.script, in support of arsd.cgi.

<main>
	<%=HTML some_var_with_html %>
	<%= some_var %>

	<if-true cond="whatever">
		whatever == true
	</if-true>
	<or-else>
		whatever == false
	</or-else>

	<for-each over="some_array" as="item" index="idx">
		<%= item %>
	</for-each>
	<or-else>
		there were no items.
	</or-else>

	<form>
		<!-- new on July 17, 2021 (dub v10.3) -->
		<hidden-form-data from="data_var" name="arg_name" />
	</form>

	<render-template file="partial.html" />

	<script>
		var a = <%= some_var %>; // it will be json encoded in a script tag, so it can be safely used from Javascript
	</script>
</main>

Functions available: encodeURIComponent, formatDate, dayOfWeek, formatTime, filterKeys

Members

Functions

multiReplace
string multiReplace(string what, string[] things)

Replaces things[0] with things[1] in what all at once. Returns the new string.

Structs

RenderTemplate
struct RenderTemplate

Can be used as a return value from one of your own methods when rendering websites with WebPresenterWithTemplateSupport.

Skeleton
struct Skeleton

UDA to put on a method when using WebPresenterWithTemplateSupport. Overrides the default template skeleton file name.

Template
struct Template

UDA to put on a method when using WebPresenterWithTemplateSupport. Overrides default generic element formatting and instead uses the specified template name to render the return value.

meta
struct meta

UDA to attach runtime metadata to a function. Will be available in the template.

var (from arsd.jsvar)
struct var via public import arsd.jsvar : var;

Templates

WebPresenterWithTemplateSupport
template WebPresenterWithTemplateSupport(CTRP)

Make a class that inherits from this with your further customizations, or minimally:

Meta

History

Things inside script tag were added on January 7, 2022.