This is outdated documentation for Sycamore.
For up-to-date documentation, see the latest version (v0.8).
template!
Sycamore uses the template!
macro as an ergonomic way to create complex user interfaces. You might have already seen it in the “Hello, World!” example.
The template!
macro is quite powerful. You can create nested nodes like so.
template!
Attributes (including classes and ids) can also be specified.
template!
template!
Events are attached using the on:*
directive.
template!
Templates can also be fragments.
template!
Or be empty.
template!
Interpolation
Templates can contain interpolated values. Anything that implements std::fmt::Display
will automatically be inserted as text into the DOM tree. For example:
let my_number = 123;
template!
Other templates created using the template!
macro can also be interpolated. For example:
let inner_template = template! ;
let outer_template = template! ;
The cool thing about interpolation in Sycamore is that it is automatically kept up to date with the value of the expression. Learn more about this in Reactivity.