sailfish/docs/en/docs/syntax/includes.md

49 lines
1.1 KiB
Markdown
Raw Normal View History

2020-06-19 01:53:16 -04:00
# Includes
You can also include another template inside templates using `include!` macro.
Consider the following example.
- `templates/header.stpl`
``` html
2020-06-19 01:53:16 -04:00
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="format-detection" content="telephone=no">
<link rel="icon" type="image/x-icon" href="favicon.ico">
```
- `templates/index.stpl`
``` rhtml
2020-06-19 01:53:16 -04:00
<html>
<head>
<% include!("./header.stpl"); %>
</head>
<body>
Main contents
</body>
</html>
```
Then you can see the `header.stpl` is embedded in the output.
``` html
2020-06-19 01:53:16 -04:00
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="format-detection" content="telephone=no">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
Main contents
</body>
</html>
```
Like [`std::include!`](https://doc.rust-lang.org/std/macro.include.html) macro in Rust, the provided path is interpreted as a relative path to the current template file.
!!! Warning
The path format is platform-specific. You must use `\` character as a separator on Windows.