0

Every entry in a section has a table. The table depicts sales over 7 years.

I want to create an index page that lists the title of each entry and the sales for each entry in the section.

I know how to loop through the table fields to template the table for each entry.

I know how to loop through the titles of each entry to create an index page.

But, how do I create an index page that loops through the table data for each entry?

Simple index loop:

{% for item in craft.entries.section('widgets').all() %}
    <li>{{ item.title }}</li>        
{% endfor %}

The entry table format is as follows:

{% set field = craft.app.fields.getFieldByHandle('budgetTable') %}   

        <table id="apaf" class="table table-striped table-bordered" style="width:100%">
            <thead >
                <tr>
                    {% for column in field.settings.columns %}
                    <th scope="col" style="font-weight: bold;">{{ column.heading }}</th>
                    {% endfor %}
                </tr>    
            </thead>     

            <tbody>
                {% for row in entry.budgetTable %}
                <tr>    

                    <th scope="row" style="font-weight: bold;">{{ row.widgetTitle }}</th>

                </tr>          
                {% endfor %}

            </tbody>          
        </table>
2
  • Not sure I'm following 100%. budgetTable is the name of the Table field. Does it only have 1 column with a handle of widgetTitle?
    – Brad Bell
    May 18, 2018 at 21:07
  • @Brad Bell. I only depict 1 column handle. There are actually 10.
    – Hellyar
    May 20, 2018 at 17:48

0

Your Answer

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

Browse other questions tagged or ask your own question.