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

Nested tables in normal for loops #564

Open
derekhsu opened this issue Sep 27, 2024 · 3 comments
Open

Nested tables in normal for loops #564

derekhsu opened this issue Sep 27, 2024 · 3 comments

Comments

@derekhsu
Copy link

Describe your problem

I got a error message as the following lines when I put {%tr ... %} tag inside a normal for loops:

Encountered unknown tag 'tr'. Jinja was looking for the following tags: 'endfor' or 'else'. The innermost block that needs to be closed is 'for'.

More details about your problem

My template

{% for data_detail in context.data_details %}
  {{ data_detail.data_name }}
 ----------------------------------------
 | Field          | Description   |  Remark|
 | {%tr for data_field in data_detail.data_fields %} |
| ---------------------------------------- |
 | {{ data_field.field }}  | {{data_field.description}} | {{data_field.remark}} |
| ---------------------------------------- |
| {%tr endfor %}
| ---------------------------------------- |
{%- end for %}

Provide a test case

My context is listed below:

"contexts": [
...
"data_details": [
                {
                    "data_name": "DI List frame",
                    "data_fields": [
                        {
                            "field": "DI No.",
                            "description": "DI No",
                            "remark": "Display field"
                        },
                        {
                            "field": "Picking Slip No.",
                            "description": "Picking Slip No.",
                            "remark": "Display field"
                        }
                    ]
                },
...

Screenshots

image

@elapouya
Copy link
Owner

You have not given the whole data, but context.data_details requires there is another outer nested for-loop isn't it ?

@derekhsu
Copy link
Author

derekhsu commented Sep 27, 2024

You have not given the whole data, but context.data_details requires there is another outer nested for-loop isn't it ?

Original data is too large to give, so I ignore it. It looks like

context = { 
    "contexts": [
        {
            "heading": "Picking Slip Production",
            "modules": ["shjjL0400.jsp", "~rest.ssjcRestL0400"],
            "instructions": [
            ,,,
            ]
        },
        {
           "heading": "...",
           ,,,
        }
     ]

So there is a normal for loop outer of the table, such as

{% for context in contexts %}
...
{% endfor %}

@elapouya
Copy link
Owner

could you try without the dash in {%- endfor %}

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

No branches or pull requests

2 participants