1

I thought that a simple .fixedOrder(true) would make the files order in the same way as in the CMS. Instead of that, there is no output. Where I go wrong?

{% set files = craft.assets.kind('pdf,word,excel').fixedOrder(true) %}
<section class="bestanden">
    <div class="col-12-md">
        <div class="documenten">
            <ul>
                {% for file in files %}
                <li>
                   <i class="fa fa-file-{{ file.kind }}-o"></i> <a href="{{ file.url }}" target="_blank">{{ file }}</a>
                </li>
                {% endfor %}
            </ul>

        </div>
    </div>
</section>
4

fixedOrder only works with the id param. (If fixedOrder is true and id is set to a list of IDs, it will return the elements in the exact order that the IDs were listed.) It’s currently not possible to query elements in a fixed order based on any other params.

For your use case, the |group filter should work nicely:

{% set kinds = ['pdf', 'word', 'excel'] %}
{% set filesByKind = craft.assets.kind(kinds)|group('kind') %}

<section class="bestanden">
    <div class="col-12-md">
        <div class="documenten">
            <ul>
                {# Loop through the file kinds in the order we want #}
                {% for kind in kinds %}
                    {% for file in filesByKind[kind] %}
                        <li>
                           <i class="fa fa-file-{{ kind }}-o"></i> <a href="{{ file.url }}" target="_blank">{{ file }}</a>
                        </li>
                    {% endfor %}
                {% endfor %}
            </ul>
        </div>
    </div>
</section>

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.