1

I've set up a print template for furniture labels.
I let my client print the labels with a special Link like

/label?ids="x|y|z"

It all works good. Now he sometimes wants to print the same label multiple times, so he and I tried the following:

/label?ids="x|x|x|y|z|z|z"

The underlying code is the following:

{% set ids = craft.request.param('ids')| split('|')|join(',') %}
{% set params =
    {
        section: 'furniture',
        limit : null,
        id: ids

    }
%}
{% paginate craft.entries(params) as entries %}
{% for entry in entries %}
     ...
{% endfor %}

This will only display x and z one time.

Is there a way around this?

Any help appreciated.

3

I would write something like this:

{% set ids = craft.request.param('ids')| split('|') %}
{% for id in ids %}
    {% set entry = craft.entries.id(id).first() %}
    …
{% endfor %}

Alternatively, to reduce the queries, store all the entries in a variable and then loop through ids and find the right match in this smaller set.

|improve this answer|||||
  • Don't you need to add .first to craft.entries since it returns an object? – Ryan Sep 27 '17 at 15:34
  • Yes, right, edited. – Alessio Breviglieri Sep 27 '17 at 15:40
  • You need a dot before first()! – Ryan Sep 27 '17 at 15:59
  • Hi, this worked like a charm. And yes, please add the the dot before first(). Thanks a lot! – outline4 Sep 27 '17 at 21:28

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.