Ootempl.ConditionalRenderer (ootempl v0.4.0)
Applies {{if}} / {{else}} / {{endif}} sections to a parsed document part
(body, header, footer, notes).
Two forms are supported:
- Inline: all of a section's markers sit in one paragraph, e.g.
Dear {{if formal}}Sir{{else}}friend{{endif}},. Only the text (and any run content such as breaks or images) between the markers is kept or removed; the rest of the paragraph is untouched. - Paragraph-level: each marker sits in a paragraph of its own, and the paragraphs between them are kept or removed. The marker paragraphs must be siblings (e.g. all in the body, or all in one table cell) and hold nothing but markers; otherwise an error is returned rather than deleting content that happens to share a paragraph with a marker.
Sections are processed innermost first. Nodes are addressed by their path in the tree, so identical-looking paragraphs elsewhere are never affected.
Summary
Functions
Processes every conditional section in root.
Types
Functions
@spec process(Ootempl.Xml.xml_element(), map()) :: {:ok, Ootempl.Xml.xml_element()} | {:error, term()}
Processes every conditional section in root.
Returns {:ok, root} with sections applied, or {:error, reason} where
reason is one of:
{:conditional_validation_failed, reason}- markers are unbalanced{:conditional_evaluation_failed, condition, reason}- the condition could not be evaluated against the data{:conditional_marker_not_alone, paragraph_text}- a marker of a multi-paragraph section shares its paragraph with other text{:conditional_section_spans_containers, condition}- a multi-paragraph section's markers are not siblings (e.g. one is inside a table)