Closed gslender closed 1 year ago
For reference, the template and values parse correctly using an online parser http://jinja.quantprogramming.com/
These are differences (not yet documented) from the original version - int
filter accepts only String
's.
This filter is not needed if the values are integers or for comparison.
Of course you can overwrite int
filter via Environment
.
Of course you can overwrite
int
filter viaEnvironment
.
Can you point to an example or provide a hint ??
Unfortunately I cannot change the template or the values - I need the Jinja to work similar to the online version. Are you able to assist?
Yes, for example:
var env = Environment(
filters: {
// same as doInteger arguments with different value type
'int': (Object? value, {int defaultValue = 0, int base = 10}) {
print(value.runtimeType);
if (value == null) {
return defaultValue;
}
if (value is int) {
return value;
}
if (value is num) {
return value.toInt();
}
if (value is String) {
return int.tryParse(value, radix: base) ?? defaultValue;
}
throw TypeError();
},
},
);
I tried this and something similar. There is now something wrong with the IF condition as it simply returns
int
int
int
Are you able to try the sample code I provided as it doesn't seem to work as expected.
EDIT: Expected result is 50
I put print
to show that it works.
How it's equal to 50 if your value is 0. First if
.
I believe this has resolved the issue for me. Thank you !!
The following code produces an error (see below) and yet it should produce a valid result of 0
Error is produced as follows...