Skip to main content Link Search Menu Expand Document Toggle dark mode Copy Code (external link)
paperwork.help

Names : Data and Variable Names

A name at the start of an expression refers to the data added to the document, or to a template variable.


On this page

Syntax

{{name}}
{{name.property}}

Data names

Each call to WithData(name, value) on the document builder adds a value that the template refers to by that name. model is the conventional name for the main data, but any name can be used.

await factory.NewDocument()
    .WithLayoutFile("report.html")
    .WithData("model", report)
    .WithData("title", "Quarterly Report")
    .SaveAsync("report.pdf");
<h1>{{title}}</h1>
<p>{{model.customer.name}}</p>

Names are available everywhere in the template - inside loops and with blocks too - so ../ is not needed to reach them.

Fields added with WithField(id, value) are available as {{$fields["id"]}}.


Template variables

A value stored with a <var> element is also referred to by its name. See the var element.

<var data-id='total' data-value='{{sumOf(model.items, .price)}}' />
<p>Total: {{total}}</p>

Notes

  • Names are case sensitive: is not.
  • A name that has not been set gives no value, and nothing is output. Use ?? to give a default, e.g. {{title ?? 'Untitled'}}.

See Also