<p>James’s answer is correct, if there's only one list of items. I'm going to propose a derivative solution, in case you're dealing with an abstract set of elements (like a common pattern across many Products’ Variants).</p>
<pre><code>{% set finishes = product.variants %}
{% set powderCoatedSuffix = 'PC' %}

&lt;ul&gt;
  {# Output the variants that *don't* end with `PC`: #}
  {% for variant in variants | filter(v =&gt; v.sku[-2:] != powderCoatedSuffix) %}
    &lt;li&gt;{{ variant.title }}: {{ variant.sku }}&lt;/li&gt;
  {% endfor %}

  {# Then, output those that *do*: #}
  {% for variant in variants | filter(v =&gt; v.sku[-2:] == powderCoatedSuffix) %}
    &lt;li&gt;{{ variant.title }}: {{ variant.sku }}&lt;/li&gt;
  {% endfor %}
&lt;/ul&gt;
</code></pre>
<p>The only trickery here is the short syntax for the <a href="https://twig.symfony.com/doc/3.x/filters/slice.html" rel="nofollow noreferrer"><code>slice</code></a> filter—in this case, taking the last two characters of the string.</p>

CC BY-SA 4.0
2020-08-20T22:09:50.550Z
2020-08-21T00:09:06.680Z
2020-08-21T00:09:06.680Z
August Miller
<p>How would you like to identify that particular entry? If you're happy to hardcode its id, then I'd do it like this with the <a href="https://craftcms.com/docs/3.x/dev/filters.html#filter" rel="nofollow noreferrer">filter</a> filter and the <a href="https://craftcms.com/docs/3.x/dev/filters.html#without" rel="nofollow noreferrer">without</a> filter:</p>
<pre><code>{% set allEntries = craft.entries.section('products').all() %}
{% set pcEntry = allEntries|filter(item =&gt; item.id = 1234) %}
{% set entriesWithoutPC = allEntries|without(pcEntry) %}
</code></pre>
<p>You can now output those however/wherever you like, e.g.</p>
<pre><code>&lt;ul&gt;
  {% for product in entriesWithoutPC %}
    &lt;li&gt;{{ product.title }}&lt;/li&gt;
  {% endfor %}
  &lt;li&gt;{{ pcEntry[0].title }}&lt;/li&gt;
&lt;/ul&gt;
</code></pre>

CC BY-SA 4.0
2020-08-20T08:58:00.830Z
2020-08-20T08:58:00.830Z
James Smith
<p>I have a website where I want to show Power Coat (<code>-PC</code>) options <em>at the end of a list</em>. The data goes into Craft in an unpredictable order, from a third-party service, so I am responsible for organizing it in the front-end.</p>
<p>Is there a way I can split out or force the <strong>-PC</strong> items to always appear at the end of the list, in my template?</p>
<p><a href="https://i.sstatic.net/9KSUk.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/9KSUk.png" alt="enter image description here" /></a></p>

<templating><forloop>
How can I ensure certain items always display at the end of a list?
# How can I ensure certain items always display at the end of a list?

(Asked by: username_0 on 2020-08-19)

I have a website where I want to show Power Coat (`-PC`) options *at the end of a list*. The data goes into Craft in an unpredictable order, from a third-party service, so I am responsible for organizing it in the front-end.

Is there a way I can split out or force the **-PC** items to always appear at the end of the list, in my template?

[![enter image description here](https://i.sstatic.net/9KSUk.png)](https://i.sstatic.net/9KSUk.png)

**Tags:** templating, forloop


---

## 2 answers

### Answer by username_1 on 2020-08-20. Score: 1

James’s answer is correct, if there's only one list of items. I'm going to propose a derivative solution, in case you're dealing with an abstract set of elements (like a common pattern across many Products’ Variants).
{% set finishes = product.variants %}
{% set powderCoatedSuffix = 'PC' %}


  {# Output the variants that *don't* end with `PC`: #}
  {% for variant in variants | filter(v => v.sku[-2:] != powderCoatedSuffix) %}
    {{ variant.title }}: {{ variant.sku }}
  {% endfor %}

  {# Then, output those that *do*: #}
  {% for variant in variants | filter(v => v.sku[-2:] == powderCoatedSuffix) %}
    {{ variant.title }}: {{ variant.sku }}
  {% endfor %}


The only trickery here is the short syntax for the slice filter—in this case, taking the last two characters of the string.


---

### Answer by username_2 on 2020-08-20. Score: 1

How would you like to identify that particular entry? If you're happy to hardcode its id, then I'd do it like this with the filter filter and the without filter:
{% set allEntries = craft.entries.section('products').all() %}
{% set pcEntry = allEntries|filter(item => item.id = 1234) %}
{% set entriesWithoutPC = allEntries|without(pcEntry) %}

You can now output those however/wherever you like, e.g.

  {% for product in entriesWithoutPC %}
    {{ product.title }}
  {% endfor %}
  {{ pcEntry[0].title }}


---

