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.
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
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>
Statamic version: 3.0.40 Pro
PHP version: 7.4.9
Fresh install from statamic/statamic
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:
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