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 >
                    {% for column in field.settings.columns %}
                    <th scope="col" style="font-weight: bold;">{{ column.heading }}</th>
                    {% endfor %}

                {% for row in entry.budgetTable %}

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

                {% endfor %}

  • 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 '18 at 21:07
  • @Brad Bell. I only depict 1 column handle. There are actually 10. – Hellyar May 20 '18 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.