45 lines
774 B
Markdown
45 lines
774 B
Markdown
# Template Syntax Overview
|
|
|
|
## Tags
|
|
|
|
- `<% %>`: Inline tag, you can write Rust code inside this tag
|
|
- `<%\mode %>`: Evaluate the Rust expression and outputs the value into the template, escaped according to `mode`
|
|
- `<%- %>`: Evaluate the Rust expression and outputs the unescaped value into the template
|
|
- `<%# %>`: Comment tag
|
|
- `<%%`: Outputs a literal '<%'
|
|
|
|
## Condition
|
|
|
|
```rhtml
|
|
<% if messages.is_empty() { %>
|
|
<div>No messages</div>
|
|
<% } %>
|
|
```
|
|
|
|
## loop
|
|
|
|
```rhtml
|
|
<% for (i, msg) in messages.iter().enumerate() { %>
|
|
<div><%\html i %>: <%\html msg %></div>
|
|
<% } %>
|
|
```
|
|
|
|
## Includes
|
|
|
|
```rhtml
|
|
<% include!("path/to/template"); %>
|
|
```
|
|
|
|
## Filters
|
|
|
|
```rhtml
|
|
<%- message | upper %>
|
|
```
|
|
|
|
```json
|
|
{
|
|
"id": <%- id %>,
|
|
"comment": "<%\json comment %>"
|
|
}
|
|
```
|