mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
doc: document $tmpl
This commit is contained in:
parent
c537578481
commit
6804fdaa56
50
doc/docs.md
50
doc/docs.md
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user