I have something I can not get my head around.

This works as expected:

.relatedTo(['and',{targetElement:22},{targetElement:33}])

But when I am building an array to use as relation criteria like so:

{% set related = [{targetElement:22},{targetElement:33}] %}

.relatedTo(['and',related])

Nothing returns.

It’s pretty late here in Berlin and I might be missing something simple but can not see what exactly. Anyone?

up vote 2 down vote accepted

I don’t know what it is – I swear: every time – but the next thing I tried, immediately after posting the question was this:

{% set related = ['and',] %}
{% for relation in relations %}
    {% set related = related|merge([{targetElement:relation}]) %}
{% endfor %}

{% paginate craft.entries
    .section('documents')
    .relatedTo(related)
    as entries %}   

That works.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.