Cms: Sort does nothing on aliased entries

Created on 3 Feb 2021  路  8Comments  路  Source: statamic/cms

Bug Description

If I pass a list of entries to the partial as

{{ if events }}
    {{ partial:link_list :items="events"}}
{{ /if }}

and then try to sort this as

        <div class="row mx-auto flex">
            {{ items sort="title:asc" }}

            <div class="md:col-3 xs:col-6 flex">
                {{ if movie }}
                    {{ partial:link_movie_grid }}
                {{ else }}
                    {{ partial:link_grid }}
                {{ /if }}
            </div>
            {{ /items }}
        </div>

Nothing happens the list gets printed in the same order as it did before.

How to Reproduce

Create a template that has a partial and pass a set of entries to the partial as a variable, then try and sort the set inside the partial

Extra Detail

template:

{{ partial:header }}
{{ if content }}
    {{ partial:text_in_center :text="content" style="no-icon"}}
{{ /if }}
{{ if programs }}
    {{ partial:cards :cards="programs"}}
{{ /if }}
{{ if events }}
    {{ partial:link_list :items="events"}}
{{ /if }}
{{ partial:image_grid_slider :items="partners_slides"}}

partial:

<section class="component link-list">

    <div class="container">
        {{ if event_list_title }}
        <div class="row" >
            <div class="col-12">
                <h2 class="h1 big font-OddeeNo2">
                    {{ event_list_title }}
                </h2>
            </div>
        </div>
        {{ /if }}

        <div class="row mx-auto flex">
            {{ items sort="title:asc" }}

            <div class="md:col-3 xs:col-6 flex">
                {{ if movie }}
                    {{ partial:link_movie_grid }}
                {{ else }}
                    {{ partial:link_grid }}
                {{ /if }}
            </div>
            {{ /items }}
        </div>
    </div>
</section>

Environment

Statamic version: 3.0.40 Pro
PHP version: 7.4.9

Fresh install from statamic/statamic

bug

All 8 comments

Doesn't seem to work _outside_ the partial either. Can you confirm that? I think the partial isn't thee issue, but rather the sort modifier when applied to an Entries collection variable.

I've got this fixed in https://github.com/statamic/cms/pull/3363. Just needs a team review.

yes it looks like this effects more than just partials

I have a product entry (products collection) which has multiple reviews (linked entries).

Now when i'm looping:
{{ reviews }}
...
{{ /reviews }}

Everything works fine.

I would like to sort reviews by date {{ reviews sort="date" }} but that it not working.

I posted the above on Discord, this is probably the same bug?

Try manually applying the change in #3363 to see if it solves your issue.
Add the new code to vendor/statamic/cms/src/Modifiers/CoreModifiers.php

@jasonvarga tested this and no changes for the ordering.

I modified my code to match @radovanobal

product.antlers.html

{{ if reviews }}
  {{ partial:partials/review_listing :items="reviews" }}
{{ /if }}

partial:

<div class="space-y-5">
        <ul class="divide-y divide-gray-200">
            {{ items sort="date:asc" }}
            <li class="py-4">
                <div class="flex space-x-3">
                    <div class="flex-1 space-y-1">
                        <div class="flex items-center justify-between">
                            <span class="text-sm font-medium">{{ title }} {{ partial:partials/stars rating="{ score }" }}</span>
                            <p class="text-sm text-gray-500">{{ date format="d.m.Y" }}</p>
                        </div>
                        <p class="text-sm text-gray-500">{{ content }}</p>
                    </div>
                </div>
            </li>
            {{ /items }}
        </ul>
    </div>

changing the sort="anything" doesnt change ordering. If i leave it only {{ items }}, then it seems to use manual orderable order (even its turned off)

My product.md has these:
```
reviews:

  • 5b161ec2-f9ae-471f-8842-f55904ae595d
  • 7beedb9b-ff32-4a3e-9b3f-823a184aefba
  • 7f652456-5890-47e0-8c50-9f8d4e0d68a8
  • 410c1dfc-1b96-4b11-86ce-1e413aaeb51b
  • 1ce664e8-6877-4f5c-8447-43c962a3d838
  • 7e2052c9-b6e3-45e1-a32b-fb2e989e5296
  • c67731f7-1e04-4915-bb4f-4e3fed24bd88
    .... +100 more
    ```

Not sure if this is related to this problem, but if I add {{ items | count }} to partial (outside of the loop) to display total amount of reviews, it breaks the {{ items }} loop

Statamic 3.0.46
PHP 7.4.8

@Hesesses The count issue is completely unrelated, but confirmed. I opened a separate issue for that here: https://github.com/statamic/cms/issues/3374

@Hesesses and the reason the fix wasn't working is because i was testing with the collections tag and you had Entries fieldtype data. The PR has been updated to work with your use case now too. https://github.com/statamic/cms/pull/3363/files

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aerni picture aerni  路  3Comments

ReneWeCode picture ReneWeCode  路  3Comments

wm-simon picture wm-simon  路  3Comments

aerni picture aerni  路  3Comments

AndreasSchantl picture AndreasSchantl  路  3Comments