If I am using the Index helper Is it possible to make the count start at 1 rather than 0. Both:
{@idx}{.}{/idx}
and
{$idx}
are zero based.
Does anyone know a way to do this?
It would be perfect if you could just do:
{$idx + 1}
but obviously that won't work.
I guess you can use math helper in combination with $idx:
{@math key=$idx method="add" operand="1"/}
To make a use of @math in dust templates you need to add dust helpers which is by default excluded from dust core package.
The specific syntax that you need in order to "load" the dust helpers in node is:
var dust = require('dustjs-linkedin');
dust.helper = require('dustjs-helpers');
Incase you cannot add these helpers, which would be really strange decision, still you can create your own function in current code base like this which can be used instead of @gt or @math
var baseContext = dust.makeBase({
position: function(chunk, context) {
return context.stack.index + 1;
},
});
Now you can use {position} instead of ${idx} which will count the loop from 1 to n.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With