Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way to concat numbers with string? #275

Open
Yrds opened this issue Aug 1, 2023 · 1 comment
Open

Is there any way to concat numbers with string? #275

Yrds opened this issue Aug 1, 2023 · 1 comment

Comments

@Yrds
Copy link

Yrds commented Aug 1, 2023

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?

@pathmapper
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants