From 6804fdaa5678ff24085b24b69c1d58fe65ff322c Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Mon, 1 Feb 2021 15:45:45 +0100 Subject: [PATCH] doc: document $tmpl --- doc/docs.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/doc/docs.md b/doc/docs.md index 31cab5d38d..b421ce1521 100644 --- a/doc/docs.md +++ b/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 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 ```v