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

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

	<if-true cond="whatever">
		whatever == true
		whatever == false

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

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

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


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

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



string multiReplace(string what, string[] things)

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

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.

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.


interface TemplateLoader

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


struct RenderTemplate

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

struct Skeleton

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

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.

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;


template WebPresenterWithTemplateSupport(CTRP)

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



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.

Suggestion Box / Bug Report