What are Templates?

Templates can mean many things to many different people, but in Fuchsia, templates mean dynamically rendered HTML or XML. This is accomplished by using the Go Template Language and all syntax is supported.

The powerful part of Templates is that you can have data from your collections injected into your template to have them rendered with live data.

Required Variables

Templates have a concept of including live data. But how do we inject and access this data? In the template user interface or through the API, you have the option to add required variables that must be included in the API request to render the template. For example, if you want to have a variable called Employees in your template, then you would add that to your list of required variables.

Then when calling the template through the API, you would need to provide a record ID for that variable name - as a query parameter. Like this: include[<record id here>]=Employee

For example, let's say you have a Model called Person, with fields Name, Age, Photo. Also, you have a collection called People that perhaps stores all your employee records.

If we wanted to create a web page to show an employee record that is inside the People collection, we would create a template like this:

<section style="border: 1px solid black">
{{ with .Employee }}
<h1>{{ .Name }}</h1>
<img src="{{ .Photo.FullURL }}" />
<p>{{ .Name }} is {{ .Age }} years old</p>
{{ end }}

This is assuming you have added a Required Variable to the template through the UI or through the API which will force any rendering of this template to include the variable Employee and gives it access to the record.

Check out our Template API docs, and the official Go Template docs for more information.