documentation

This commit is contained in:
Daniel Arbuckle 2023-01-19 10:09:10 -08:00
parent c282daf907
commit 4c009c6b49
2 changed files with 28 additions and 0 deletions

View File

@ -5,6 +5,7 @@
- `<% %>`: Inline tag, you can write Rust code inside this tag
- `<%= %>`: Evaluate the Rust expression and outputs the value into the template (HTML escaped)
- `<%- %>`: Evaluate the Rust expression and outputs the unescaped value into the template
- `<%^ %>`: Evaluate the Rust expression producing a `TemplateOnce` value, and render that value into the template
- `<%# %>`: Comment tag
- `<%%`: Outputs a literal '<%'

View File

@ -105,3 +105,30 @@ If you want to render the results without escaping, you can use `<%- %>` tag or
``` rhtml
<% let result = %><%= 1 %><% ; %>
```
## Component block
Rust expression inside `<%^ %>` tag is evaluated and then rendered by
calling its `render_once()` method. If the value does not have an
appropriate method, a compile-time error will be reported.
This makes it easy to use types which are `TemplateOnce` as components
which can be embedded into other templates.
=== "Template A"
``` rhtml
<strong>A <%= val %></strong>
```
=== "Template B"
``` rhtml
B <%^ A { val: "example" } %>
```
=== "Result"
``` text
B <strong>A example</strong>
```