Data-binding
Learn how to use data-binding in your forms and pages.
Data-binding, <div>
and <span>
elements
<div>
and <span>
elementsCreate wrapping <div>
elements by putting content inside pairs of :::
. The content inside can be any valid Markdown, such as headings, paragraphs, lists, form fields, etc. Class names and other attributes are supported via [...]
(learn more). Moreover, you can bind one or more fields to a <div>
element by adding the names of the fields inside {$...$}
(separated by spaces), and placing this within the [...]
. This means that whenever the value of a binded field changes, the content inside the <div>
will be automatically re-rendered.
The templating is done using Nunjucks, so its entire list of features such as if-else statements, loops, filters, etc. are fully supported. You can also bind a single field to a <span>
element using {$ field $}
. This is obviously not as flexible, but it is simple, and can be used inside paragraphs, headings, list items, etc.
Moreover, you can use data-binding to dynamically update class names and other attributes based on user input. In the example below, the color
and background-color
of the paragraph and the list within the <div>
element will change depending on what is chosen by the user.
Here's another example showing how to dynamically change the code depending on the choice of language:
Last updated