1

I have a Super Tables field, containing related entries:

Super Table with entries rows

I'd like to display the field name (ie 'English Links') in a template, but can't figure out how, the following outputs a string of values and if I try to add a handle to the row output I get 'Impossible to access an attribute ("handle") on a string variable'.

{% for row in entry.relatedArticleLinks %}
    {{ row }}
{% endfor %}

I really don't think this was written very well in the first place tbh, as the rows are hard coded:

        <div class="w-full md:w-1/3 my-1">
            <h3>English</h3>
            <ul class="list-reset">
            {% for link in entry.relatedArticleLinks.englishLinks %}
                <li><a href="{{ link.url }}" class="text-black text-sm">{{ link.title }}</a></li>    
            {% endfor %}
            </ul>
        </div>

I'm sure there's a better way of displaying this field which would allow new rows to be displayed automatically?

  • What type of field is English Links? Seem like a some kind of repeatable field with a "link" and "url?" – Alex Roper Sep 10 '19 at 7:41
1

This can be done, but it does require additional calls to query this information. It might be more efficient to hard-code this text in your template, unless you really want to make this text dynamic.

There's two concepts here. When you call entry.relatedArticleLinks you're fetching Super Table blocks that are related to the entry in question. Calling englishLinks on each of these blocks will return the content for this field - nothing about the field definition itself, such as the handle, name, or settings - just the content.

What type of field is englishLinks?

If you wanted to grab the field definition as well, you can by calling:

{% set field = craft.app.fields.getFieldByHandle('relatedArticleLinks') %}
{% set blocks = craft.superTable.getSuperTableBlocks(field.id) %}
{% set fields = blocks[0].getFields() %}

{{ fields.englishLinks.name }}
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.