Portability | portable |
---|---|
Stability | alpha |
Maintainer | John MacFarlane <[email protected]> |
Text.Pandoc.Templates
Description
A simple templating system with variable substitution and conditionals. Example:
renderTemplate [("name","Sam"),("salary","50,000")] $ "Hi, $name$. $if(salary)$You make $$$salary$.$else$No salary data.$endif$" "Hi, John. You make $50,000."
A slot for an interpolated variable is a variable name surrounded
by dollar signs. To include a literal $
in your template, use
$$
. Variable names must begin with a letter and can contain letters,
numbers, _
, and -
.
The value of a variable will be indented to the same level as the variable.
A conditional begins with $if(variable_name)$
and ends with $endif$
.
It may optionally contain an $else$
section. The if section is
used if variable_name
has a non-null value, otherwise the else section
is used.
Conditional keywords should not be indented, or unexpected spacing problems may occur.
If a variable name is associated with multiple values in the association
list passed to renderTemplate
, you may use the $for$
keyword to
iterate over them:
renderTemplate [("name","Sam"),("name","Joe")] $ "$for(name)$\nHi, $name$.\n$endfor$" "Hi, Sam.\nHi, Joe."
You may optionally specify separators using $sep$
:
renderTemplate [("name","Sam"),("name","Joe"),("name","Lynn")] $ "Hi, $for(name)$$name$$sep$, $endfor$" "Hi, Sam, Joe, Lynn."
- renderTemplate :: TemplateTarget a => [(String, String)] -> String -> a
- class TemplateTarget a
- getDefaultTemplate :: String -> IO (Either IOException String)
Documentation
Arguments
:: TemplateTarget a | |
=> [(String, String)] | Assoc. list of values for variables |
-> String | Template |
-> a |
Renders a template
class TemplateTarget a Source
getDefaultTemplate :: String -> IO (Either IOException String)Source
Get the default template, either from the application's user data directory (~/.pandoc on unix) or from the cabal data directory.