diff options
| author | Albert Krewinkel <[email protected]> | 2022-01-02 15:28:59 +0100 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2022-01-02 11:55:02 -0800 |
| commit | efdba79ad18fcbe33992878b02be25f8e9616b0c (patch) | |
| tree | 2c6f82d499bd12105f34de14d4fcf957c93ce27d /doc/custom-writers.md | |
| parent | 60fc05e2ce2dc4b0191ee98daccf301a065e2dae (diff) | |
Lua writer: allow variables to be set via second return value of `Doc`
New templates variables can be added by giving variable-value pairs as a
second return value of the global function `Doc`.
Example:
function Doc (body, meta, vars)
vars.date = vars.date or os.date '%B %e, %Y'
return body, vars
end
Closes: #6731
Diffstat (limited to 'doc/custom-writers.md')
| -rw-r--r-- | doc/custom-writers.md | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/doc/custom-writers.md b/doc/custom-writers.md index 6df603288..fb08cd120 100644 --- a/doc/custom-writers.md +++ b/doc/custom-writers.md @@ -50,3 +50,19 @@ the functions in `sample.lua` according to your needs. ``` {.lua include="sample.lua"} ``` + +# Template variables + +New template variables can be added, or existing ones +modified, by returning a second value from function `Doc`. + +For example, the following will add the current date in +variable `date`, unless `date` is already defined as either a +metadata value or a variable: + +``` lua +function Doc (body, meta, vars) + vars.date = vars.date or meta.data or os.date '%B %e, %Y' + return body, vars +end +``` |
