doc: document $tmpl

pull/8495/head
Alexander Medvednikov 2021-02-01 15:45:45 +01:00
parent c537578481
commit 6804fdaa56
1 changed files with 50 additions and 0 deletions

View File

@ -3346,6 +3346,56 @@ executable, increasing your binary size, but making it more self contained
and thus easier to distribute. In this case, `f.data()` will cause *no IO*, and thus easier to distribute. In this case, `f.data()` will cause *no IO*,
and it will always return the same data. and it will always return the same data.
#### $tmpl for embedding and parsing V template files
V has a simple template language for text and html templates, and they can easily
be embedded via `$tmpl('path/to/template.txt')`:
```v ignore
fn build() string {
name := 'Peter'
age := 25
numbers := [1, 2, 3]
return $tmpl('1.txt')
}
fn main() {
println(build())
}
```
1.txt:
```
name: @name
age: @age
numbers: @numbers
@for number in numbers
@number
@end
```
output:
```
name: Peter
age: 25
numbers: [1, 2, 3]
1
2
3
```
#### $env #### $env
```v ```v