Closed 3goats closed 8 years ago
Docs for scripts extension includes the API section which describes how to do it http://jsreport.net/learn/scripts
It would be something like this
jsreport.render({ template : { ...
scripts: [{
content: "request.template.content='hello'; done();"
}]
})
Thanks does this need to be content: "request.template.content='hello'; done();
to return some data back to the template instead of overriding the entire content ?
OK I guess it like this content: "request.data={endpoints: 'hello'}; done();"
OK I guess it like this content: "request.data={endpoints: 'hello'}; done();"
Yes that should work
So the question now is since this is:
var data = fs.readFileSync(path.join('/Users/cbourne/Development/jsreport-new', 'scratch.json').toString(), 'utf8');
var json = JSON.parse(data);
is outside of the jsreport.render
function, how do I get pass the data into the content ?
Is there an easy way to do this or do I need to something special ?
OK so this works for anyone else that needs it. The problem was that my json
variable was not global.
content: "request.data= " + JSON.stringify(json) + " ; done();"
So I have this code which is working.
However, I also have some scripts that get data from an external resource. How do I reference them in jsreport-core ?