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" />

	<document-fragment></document-fragment>

	<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.

renderTemplate
Document renderTemplate(string templateName, var context, var skeletonContext, string skeletonName, TemplateLoader loader)

Loads a template from the template directory, applies the given context variables, and returns the html document in dom format. You can use Document.toString to make a string.

serveTemplateDirectory
auto serveTemplateDirectory(string urlPrefix, string directory, string skeleton, string extension, string templateDirectory)

Serves up a directory of template files as html. This is meant to be used for some near-static html in the midst of an application, giving you a little bit of dynamic content and conveniences with the ease of editing files without recompiles.

Interfaces

TemplateLoader
interface TemplateLoader

A loader object for reading raw template, so you can use something other than files if you like.

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.

This module was added to dub on September 11, 2023 (dub v11.2).

It was originally written in July 2019 to support a demonstration of moving a ruby on rails app to D.