[Help] Jinja Table

Good day!

I have a question. My goal is to get rid of the duplicates in my print format.

Here are the examples.

Print Format: (Preview)
image
The first column should only display one data only. (in this case should only display one CLO code per row)
The second row should only display only the given data, but instead it displays all of it. (in this case the second row should only display “TEST” in all columns)

Print Format: (Jinja Code)

<div class="parent_container">
    <table style="width:100%">
        <tbody>
            <tr>
                <th>
                    <h7><strong><i>Terminal Competencies/Course Learning Outcomes</i></strong></h7>
                    <br>
                    <p style="font-weight: normal">At the end of this course, the students will be able to:</p>
                </th>
            {%- for group in doc.clo_table | groupby("department") -%}
                <td>
                    <h7> <strong>BS{{ group.grouper.upper().split()[0][0] }}{{ group.grouper.upper().split()[1][0] }}</strong> </h7>
                </td>
            {%- endfor -%}
            </tr>
            {%- for group in doc.clo_table | groupby("course_learning_outcomes_code") -%}
            <tr>
                <td>
                    {%- for item in group.list -%}
                    <h7><strong> {{ item.course_learning_outcomes_code }}</strong></h7>
                    <br>
                    {%- endfor -%}
                </td>
                

                {%- for plo_group in doc.clo_table | groupby("department") -%}
                <td>
                    {%- for item in plo_group.list -%}
                        <h7> {{ item.program_learning_outcomes_code }} </h7>

                    {%- endfor -%}
                </td>
                {%- endfor -%}
            </tr>
            {%- endfor -%}
        </tbody>
    </table>
    <br> <br>
</div>

Here is my Jinja code.

Child Table:


The first and second column serves as a separator for the print format. Basically it groups them by Code and Department.

Thank you so much guys :slight_smile:

1 Like

Hi @m0L3cuL3,

I think if you have not checked so check it.
https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-filters.groupby

Maybe it’s helpful to you.

Thanks.

1 Like

Hi @NCP

Thanks I manage to fix the duplicates but there are duplicates in my other columns.

image
As you can see I managed to fixed the CLO codes, but in the department columns it duplicates it.
Row 2 or (CLO 2) should only display “TEST” in each department columns.

Jinja Code:

<div class="parent_container">
    <table style="width:100%">
        <tbody>
            <tr>
                <th>
                    <h7><strong><i>Terminal Competencies/Course Learning Outcomes</i></strong></h7>
                    <br>
                    <p style="font-weight: normal">At the end of this course, the students will be able to:</p>
                </th>
                {%- for group in doc.clo_table | groupby("department") -%}
                <td>
                    <h7> <strong>BS{{ group.grouper.upper().split()[0][0] }}{{ group.grouper.upper().split()[1][0] }}</strong> </h7>
                </td>
                {%- endfor -%}
            </tr>
            
            
            {%- for clo in doc.clo_table | groupby("course_learning_outcomes_code") -%}
            <tr>
                <td>
                    <h7><strong> {{ clo.grouper }}</strong></h7>
                    <br>
                </td>
                {%- for plo in doc.clo_table | groupby("department") -%}
                <td>
                     {%- for item in plo.list -%}
                    <h7> {{ item.program_learning_outcomes_code }} </h7>
                     {%- endfor -%}
                </td>
                {%- endfor -%}
            </tr>
            {%- endfor -%}
        </tbody>
    </table>
    <br> <br>
</div>

Tbh, I don’t really know why it keeps duplicating. Is there any way to filter or group the department columns where it relies on the CLO codes? Idk if that makes sense.
Thank you in advance :slightly_smiling_face:

There is a jinja modifer

{% for x in a|unique %}
    <li>{{ x }}</li>
  {% endfor %}
2 Likes

@FHenry @NCP Thank you so much, It fixed my issue. :blush: