html - Closure Templates: setting global variable from passed paramater in soy file -
is there way set global variables in .soy file parameters passed in .html? templates able access global variables avoid redundancy of repassing same parameters each template.
for example work this:
html:
document.write(wet4.gcweb.setglobal({templatedomain:"example.ca"})); soy:
/** * test. * @param templatedomain */ {template .setglobal} globalvariable = $templatedomain {/template} and globalvariable accessed other templates
my experience google closure templates limited java backend in atlassian plugin development, however, templates use reserved variable global data: $ij. following taken injected data section of documentation:
injected data data available every template. don't need use
@paramdeclaration injected data, , don't need manually pass called subtemplates.given template:
{namespace ns autoescape="strict"} /** example. */ {template .example} foo {$ij.foo} {/template}in javascript, can pass injected data via third parameter.
// output 'foo injected foo'. output = ns.example( {}, // data null, // optional output buffer {'foo': 'injected foo'}) // injected datain java, using tofu backend, can inject data using setijdata method on renderer.
soymapdata ijdata = new soymapdata(); ijdata.put("foo", "injected foo"); soytofu tofu = ...; string output = tofu.newrenderer("ns.example") .setijdata(ijdata) .render();injected data not scoped function parameters. templates below behave in same way ".example" template above despite lack of data attribute on call tag.
{namespace ns autoescape="strict"} /** example. */ {template .example} {call .helper /} {/template} /** helper. */ {template .helper private="true"} foo {$ij.foo} {/template}
Comments
Post a Comment