Defect #141
Array's and objects
Start date:
08/28/2010
Due date:
% Done:
100%
Estimated time:
Browser (if web client):
Description
I try to pass an array by adding it as a property of the context array and #foreaching it in the template but the content of the array seems te be empty.
No errors thrown, the rest of the template is processed properly
If I create another object and embed it in the context object, I am able to access it like $subject.property but again, #foreach can't handle it.
It seems to crash the plugin. No errors thrown, no output.
History
Updated by Patrick Talbot over 14 years ago
- Category set to velocity
- Status changed from New to Closed
- Assignee set to Patrick Talbot
- % Done changed from 0 to 100
Fixed with R374
Note that due to a limitation in Velocity, array values are available using a get(index) syntax and not a [index] syntax.
This test script will work fine from v1.3.1 release and more.
var context = {
obj: {
vara: "a",
varb: false,
varc: 22,
vard: [1,2,3],
vare: {a: 1, b: 'b'}
},
array: ["b", true, 33]
};
var template = "#foreach($key in $obj)\n";
template += "$key: $obj.get($key)\n";
template += "#end\n\n";
template += "$array.get(1)\n\n"
template += "#foreach($v in $array)\n";
template += "$v: $array.get($v)\n";
template += "#end\n";
application.output(plugins.VelocityReport.evaluateWithContext(template,context));
Output:
vara: a varb: false varc: 22.0 vard: [1.0, 2.0, 3.0] vare: {a: 1.0, b: b} true 0: b 1: true 2: 33.0