This module provides Mustache (or Handlebars) like template syntax.
An Options value is used to configure rendering of a template.
Currently supports:
trim - Trim spaces around interpolated value. Defaults to Trueplaceholder - Specify placeholder text when no associated value is found in
template parameter. Defaults to empty string ("").Compiles string into a template function.
To render template with some parameters, use run.
tmpl : Template
tmpl =
compile defaultOptions <|
"Hello, {{name}}"The default configuration for a template.
Apply template function to some parameters and get rendered text.
See Template.Params module to how you can interact with Params value.
params : Params
params =
Params.fromList
[ ( "browser", "Firefox" )
, ( "language", "JavaScript" )
]
t : Template
t =
compile defaultOptions "My favorite is {{browser}} and I can use {{language}}!"
str : String
str =
run params t
-- "My favorite is Firefox and I can use JavaScript!"Render template string directly with given parameters and options.
Useful when you do not need the compiled function. A quicker way to run!
render
(Params.fromList [( "food", "Okonomiyaki" )])
defaultOptions
"Give me some {{food}}"Same as render but uses default options.
The quickest way to run!
renderWithDefault
(Params.fromList [( "animal", "dog" )])
"How this {{animal}} sleep?"
A compiled template function, accepts
Paramsand render string.Can be configured by
Options.