Update documentation

This commit is contained in:
Vince Pike 2023-01-24 15:27:03 -05:00
parent 32c9d461e5
commit 13d6d06955
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>
```