diff --git a/uppsrc/Skylark/StdLib.icpp b/uppsrc/Skylark/StdLib.icpp index 033169129..1b1cf8983 100644 --- a/uppsrc/Skylark/StdLib.icpp +++ b/uppsrc/Skylark/StdLib.icpp @@ -65,6 +65,23 @@ Value VariablesSet(const Vector&, const Renderer *r) return Raw(html); } +Value Render(const Vector& arg, const Renderer *r) { + if (arg.GetCount() < 1) + return ""; + // create new Renderer, as we can not modify the one currently used + Renderer rr; + // copy variables so they are available in the rendered template too + for(int i = 1; i < r->Variables().GetCount(); i++) { + rr(r->Variables().GetKey(i), r->Variables()[i]); + } + // add arguments as variables + for(int i = 1; i < arg.GetCount(); i++) { + rr("_"+IntStr(i), arg[i]); + } + // render the template passed in first argument + return rr.Render(AsString(arg[0])); +} + INITBLOCK { Compiler::Register("cycle", Cycle); Compiler::Register("raw", RawFn); @@ -72,6 +89,7 @@ INITBLOCK { Compiler::Register("post_identity", PostIdentity); Compiler::Register("js_identity", JsIdentity); Compiler::Register("set", VariablesSet); + Compiler::Register("render", Render); }; }; diff --git a/uppsrc/Skylark/src.tpp/Witz$en-us.tpp b/uppsrc/Skylark/src.tpp/Witz$en-us.tpp index efd58be07..b80fdda1f 100644 --- a/uppsrc/Skylark/src.tpp/Witz$en-us.tpp +++ b/uppsrc/Skylark/src.tpp/Witz$en-us.tpp @@ -248,7 +248,7 @@ element&] [s0;3 &] [ {{4495:5505h1;@(216) [s0; Function] :: [s0; Description] -::^@2 [s0; [*C cycle(i, p0, p1, ..., pn)]] +::^@2 [s0; [*C cycle(i, p1, ..., pn)]] :: [s0; Returns p`[i mod n`].] :: [s0; [*C raw(text)]] :: [s0; Returns argument as `"raw`" text that is not supposed to be @@ -264,5 +264,10 @@ CSRF attack prevention.] AJAX POSTs.] :: [s0; [*C set()]] :: [s0; Returns html formatted list of current shared variables. Useful -for debugging.]}}&] +for debugging.] +:: [s0; [*C render(witz`_template, p1, ...)]] +:: [s0; Inserts another template into output. Current variables are +copied to new template, parameters p1... are copied as `$`_1, +`$`_2 etc. This is similar to using #include, but with it is +easier to pass arguments to included template this way.]}}&] [s0; ]] \ No newline at end of file