Skip to content

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

Open
@Yrds

Description

@Yrds

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions