inja icon indicating copy to clipboard operation
inja copied to clipboard

Is there any way to concat numbers with string?

Open Yrds opened this issue 11 months ago • 1 comments

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?

Yrds avatar Aug 01 '23 18:08 Yrds