1

I am stuck in a simple problem but not able to figure it. I am not sure if this is the right place to ask the question on a package in Rust. Most of the time, in the template, we will want to transform our data. For example, I wanted to concat n arrays in one line. I can use ~ operator only if I know the number of arrays. Below is the requirement I am looking for,

{% macro generate_table(table) %}
    {% for rows in 0..table.length %}
        {{ table[table.col_header[0]][row] ~ "     ||      " ~ [table.col_header[1]][row] }}
    {% endfor %}
{% endmacro input %}

I want to do.

{% macro generate_table(table) %}
    {% for rows in 0..table.rlength %}
        {% for cols in 0..table.clength %}
            {{ arr.insert(table[table.col_header[cols]][row]) }}
        {% endfor %}
        {{ arr | join(sep="     ||      ") }}
    {% endfor %}
{% endmacro input %}

1 Answer 1

5

I figured it out. Using concat(with="")

{% macro generate_table(table) -%}

    {% for row in [0,1,2] -%}
        {% set_global row_val = [] -%}
        {% for cols in [0,1,2] -%}
            {% set_global row_val = row_val | concat(with= table.col_values[table.col_header[cols]][row]) -%}
        {% endfor -%}
        {{ row_val | join(sep=" ") }}
    {% endfor -%}
{% endmacro generate_table -%}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.