Render Web Template Event
Dittofi lets you take an existing or new HTML template and copy and paste that template into your app. You can then use this template and populate it with variable data that you include within your data models. For example, you might have a table of products and want to use an existing HTML design.
To do this, you can use the render web template event. This can be set up in 5 quick and easy steps.
  1. 1.
    Step 1. create an HTML template
  2. 2.
    Step 2. create a render web template endpoint
  3. 3.
    Step 3. create a render web template action
  4. 4.
    Step 4. add a create a render web template event
  5. 5.
    Step 5. build and test

Step 1. create an HTML template

Go to the templates tab inside the Dittofi Design Studio. This can be found under the wrench icon in the Dittofi Design Studio.
Inside here, you can create a new HTML template in the folder Backend > Views. Below we show a new template called "My First HTML Template".
The test HTML is below.
// Test HTML for template
<h1>Hello world!</h1>

Step 2. create a render web template endpoint

Go to the endpoints tab and create a new endpoint by clicking the + New Endpoint button. Next, give your endpoint the name "Render web template", the path "/v1/render_web_template", the description "Endpoint to render my HTML template", set the request method to GET and the response Content Type: text/html. The screenshot below shows this.

Step 3. create a render web template action

Head over to the actions tab and create a new action by clicking the "+ New Action" button. Give the action the name "Render web template" and make the trigger component and endpoint and link the trigger endpoint to the "Render web template endpoint" that we made in step 2.

Step 4. add a create a web template event

Next click the + Add Event button and add the Render web template event. Give the event the description "Render 'My first HTML template'" and choose the template that we created in Step 1.
Lastly, save the event and close the action.

Step 5. build and test

The final step is to build the code and test it. To build the code click the "Build code" button. Once the code has finished building, open the "Render web template endpoint" that we made in Step 2. and run the endpoint.
To validate that this has worked correctly, you can take the URL of the endpoint and copy and paste this into a new tab in your browser, as shown below.
Note, in technical terms the render web template event is used to do server side rendering of a templated HTML.

(Optional) add variable information

The render web template event can also be used to render variable data that you might have in your Dittofi backend. For example, a list of data stored in one of your data models e.g. blogs, user names etc.
To declare a variable you need to add curly braces like the example below.
// Adding an example of an email with a variable
<h1>Hello {{.Name}}, welcome to my hello world template!</h1>
Note supports all go template syntax (loops, if statements etc.). For more information on this, read the go docs here https://pkg.go.dev/text/template.
In the above template example, the "Name" variable can be populated by data inside the Render Web Template event that we added in Step 4. The GIF below shows how to do this. Note that the variable name needs to match the variable name.