inja
inja copied to clipboard
Is there any way to concat numbers with string?
I've trying to set a string which concat integer variables with strings and other string variables, like this example below:
page.json.coupons
is an array of objecsts
{% set page.config.description=length(page.json.coupons) + " found coupons to " + storeJson.store_name %}
But this exceptions is raising: [json.exception.type_error.302] type must be number, but is string
I did a workaround which is not the better idea, but it's working for know. But in the future I want to create a function to convert numbers to string so I can concat numbers with strings.
The ugly workaround I did:
{# Workaround to convert a number to string. TODO create a function to do that #}
{% set couponsArray = [0] %}
{% set couponsArray.0 = length(page.json.coupons) %}
{% set couponsLength = join(couponsArray, "") %}
{# Workaround end #}
{% set page.config.description=couponsLength + " found coupons to " + storeJson.store_name %}
Any thoughts on this?
There are already functions to convert strings to numbers https://github.com/pantor/inja#functions So it would be nice to have also a function which converts numbers to strings.