1

I need to get data from fields from another section. My code is:

        {% for kontaktEntry in craft.entries.section('kontakt').entry.kontakter %}
            <div>
                <a href="{{ kontaktEntry.epost }}">
                    {% set image = kontaktEntry.bilde.first() %}
                    {% if image %}
                        <img src="{{ image.getUrl() }}" width="100" height="100" alt="{{kontaktEntry.navn}}"/>
                    {% endif %}
                    <h3 class="center">{{ kontaktEntry.navn }}</h3>
                    {{ kontaktEntry.stilling }}
                </a>
            </div>
        {% endfor %}

kontakter is a matrix. I get nothing in output. What is wrong here?

  • 1
    I'm not sure that .entry is a valid parameter? I think that craft.entries.section('kontakt') contains an array with entries, so maybe you you could do .first on it? – Youniteus Aug 14 '17 at 19:03
  • Thank you, Youniteus! You are right! Publish it as an answer, so it will be voted up. craft.entries.section('kontakt').first.kontakter is a correct code. – podeig Aug 14 '17 at 21:37
3

I'm not sure that .entry is a valid parameter? I think that craft.entries.section('kontakt') contains an array with entries, so maybe you you could do .first on it, so basically I think you wanted to do this:

    {% for kontaktEntry in craft.entries.section('kontakt').first.kontakter %}
        <div>
            <a href="{{ kontaktEntry.epost }}">
                {% set image = kontaktEntry.bilde.first() %}
                {% if image %}
                    <img src="{{ image.getUrl() }}" width="100" height="100" alt="{{kontaktEntry.navn}}"/>
                {% endif %}
                <h3 class="center">{{ kontaktEntry.navn }}</h3>
                {{ kontaktEntry.stilling }}
            </a>
        </div>
    {% endfor %}

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.