diff --git a/examples/vweb/index.html b/examples/vweb/index.html
index 1fbd30b049..4391eeb248 100644
--- a/examples/vweb/index.html
+++ b/examples/vweb/index.html
@@ -1,5 +1,4 @@
-test app
-
+Test app
-
+
@hello
diff --git a/examples/vweb/vweb_example.v b/examples/vweb/vweb_example.v
index 0476db7ddd..e73de3b7f3 100644
--- a/examples/vweb/vweb_example.v
+++ b/examples/vweb/vweb_example.v
@@ -28,6 +28,7 @@ pub fn (mut app App) json_endpoint() {
pub fn (mut app App) index() {
app.cnt++
//app.vweb.text('Hello world from vweb')
+ hello := 'Hello world from vweb'
$vweb.html()
}
diff --git a/vlib/v/parser/comptime.v b/vlib/v/parser/comptime.v
index fd7fa10133..acbcfbd0de 100644
--- a/vlib/v/parser/comptime.v
+++ b/vlib/v/parser/comptime.v
@@ -113,6 +113,22 @@ fn (mut p Parser) vweb() ast.ComptimeCall {
}
}
*/
+ // copy vars from current fn scope into vweb_tmpl scope
+ for stmt in file.stmts {
+ if stmt is ast.FnDecl {
+ fn_decl := stmt as ast.FnDecl
+ if fn_decl.name == 'vweb_tmpl' {
+ body_scope := file.scope.innermost(fn_decl.body_pos.pos)
+ for _, obj in p.scope.objects {
+ if obj is ast.Var {
+ v := obj as ast.Var
+ body_scope.register(v.name, *v)
+ }
+ }
+ break
+ }
+ }
+ }
return ast.ComptimeCall{
is_vweb: true
vweb_tmpl: file