Determines how the Mustache engine renders output. Valid options:
text
: Render the output as plain text, do not do additional encoding of entities.html
: Render output as escaped HTML with entities converted for use in HTML.Create a new object configured to point to a directory of Mustache template files in iCloud Drive. When using this method, other Mustache template located in the same directory will be available to be used as partials in the rendering process.
Relative path to a directory of Mustache template files (with .mustache file extension) located in iCloud Drive/Drafts/Library/Templates
. For example to refer to templates in the directory iCloud Drive/Drafts/Library/Templates/My Mustache Templates/
, pass My Mustache Templates/
to this method.
Create a new object with a template
a valid Mustache template string
Use in combination with createWithPath(path)
to render the template using the data passsed.
The name of a template file in the directory passed to create the MustacheTemplate object. Do not include the ".mustache" file extension. For example, if you have a "Document.mustache" file in the directory, pass templateName "Document".
A Javascript object with the values to use when rendering the template. The object can have nested sub-objects.
See also:
Draft.processMustachTemplate
for rendering with Mustache similar to how those templates are rendered in actions. TheMustacheTemplate
object is for rendering with your own custom context.The MustacheTemplate object support rendering of templates using the Mustache template style.
Mustache templates offer advanced features for iterating over items, creating conditional blocks of text and more. This is still a bit of an experimental feature, please send feedback if you are finding edge cases or are interested in more functionality in this area.
The object can be used in one of two ways, by passing a specific template as a string and rendering it, or by passing a path to a subdirectory of the
iCloud Drive/Drafts/Library/Templates
folder which can contain more than one Mustache style templates (with file extension.mustache
), and then rendering them. The late method has the advantage of supporting the use of partial templates in the same folder.For details on using Mustache templates, we recommend reviewing tutorials.
About Passing Data to Templates
When rendering Mustache templates, you pass the template itself and a data object which contains the values available to insert. The data object should be a Javascript object with keys and values. Values can be basic data types (numbers, strings, dates) and also arrays or nested objects which can be iterated using conventions of the Mustache syntax.
Example