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

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

{% paginate craft.entries
    .section('documents')
    .relatedTo(related)
    as entries %}   
</code></pre>

<p>That works.</p>

CC BY-SA 4.0
2018-10-04T23:13:54.940Z
2018-10-04T23:13:54.940Z
Marcus Scheller
<p>I have something I can not get my head around.</p>

<p>This works as expected:</p>

<pre><code>.relatedTo(['and',{targetElement:22},{targetElement:33}])
</code></pre>

<p>But when I am building an array to use as relation criteria like so:</p>

<pre><code>{% set related = [{targetElement:22},{targetElement:33}] %}

.relatedTo(['and',related])
</code></pre>

<p>Nothing returns.</p>

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

<templating><relatedto>
RelatedTo "and" and arrays
# RelatedTo "and" and arrays

(Asked by: username_0 on 2018-10-04)

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?

**Tags:** templating, relatedto

---

## 1 answers

### Answer by username_0 on 2018-10-04. Score: 2 | Accepted answer

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.


---

