Clone

Multi site generator

Meet the meta-templates.

What is the generator?

Mustache is a logic-less templates, meaning that you have a limited set of options to display your content (and also a limited possibility to have errors). Usually template engines have responsibilities like dealing with translations or site configuration that have nothing related with the rendered template itself.

If you wanted to inject translations in a mustache template you would need to inject as part of the data the translations used in the page.

The generator allows you to have the best of both worlds. Keep your templates without logic, but automatically generate all the different versions of the same site with their personalizations (not only translations). For that API2HTML uses meta-templates (please let us know if you find a better name).

Understanding meta-templates

Imagine that you have a mustache template with the following content inside:

Welcome to {{ city }}

Now you want to expand your business and decide to launch the site in more languages, e.g: Spanish. You would need to create in addition the following template:

Bienvenido a {{ city }}

So, your installation would have 2 files with the same functionality that you need to maintain together. Or another option, instead of two files, you have one file but you start injecting translations along with your data. Like:

{{ I18N.welcome_to }} {{ city }}

Imagine now dealing with this context, were anywhere that you need a translation, you are passing the whole translations object.

The meta-template helps us free mustache rendering and translation handling in execution time, and allow us to declare a template that will be pre-processed before your server starts. The syntax would be as follows:

{{=<% %>=}}	<% I18N.welcome_to %> {{ city }}

Since the generator must not compile existing variables in the templates we are changing the mustache delimiters for the generator execution. We have chosen <% %> but you can just write in the file whatever you like.

Compiling this template with the required translations will make the final personalized template.

In this example we have used a translation, but you could place anything you imagine inside the variable, so this is not tied to literals only.


Continue to Generating multiple sites

← Back to New Relic integration