Answers.Body: <p>If I do a similar test:</p>
  
  <pre><code>{% set myVar = ['10032'] %}
  
  {{ dump(myVar) }}
  </code></pre>
  
  <p>That gives:</p>
  
  <pre><code>array (size=1)
    0 =&gt; string '10032' (length=5)
  </code></pre>
  
  <p>Just like yours.</p>
  
  <pre><code>{% set entryId = 10032 %}
  
  {% if entryId not in myVar %}
      {{ entryId }} not in myVar
  {% else %}
      {{ entryId }} is in myVar
  {% endif %}
  </code></pre>
  
  <p>Outputs:</p>
  
  <pre><code>10032 is in myVar
  </code></pre>
  
  <p>As expected.  Changing <code>entryId</code> to something other than 10032 gives the expected "is not in myVar".</p>
  
  <p>It should be noted that this line:</p>
  
  <pre><code>is in myVar {{ myVar }}
  </code></pre>
  
  <p>Will cause an array to string conversion error because you're telling Twig to output an array to the browser and it doesn't know how.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-22T16:03:20.833Z
Answers.Text: How would I set the string to myVar instead of the whole array? at
  `{% set myVar = block.matrixBlockField.ids() %}`
  
  Since I won't know the field id upfront normally. That way I can compare the strings later on.
Answers.UserDisplayName: Twain
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-22T16:19:03.343Z
Answers.Text: changing to {% if entry.id not in myVar[0] %} gets me a templating error.
Answers.UserDisplayName: Twain
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-23T00:31:49.333Z
Answers.Text: Sorry, I'm not following... in both your example and mine, `myVar` is set to an array with one string item in it set to "10032".
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-16T19:35:34.433Z
Answers.Text: It turns out that your answer correct. We had a plugin that would essentially iterate over it setting the id back to null.
Answers.UserDisplayName: Twain
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-17T00:40:27.900Z
Answers.Text: Glad you're all sorted!
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-19T23:03:30.563Z
Answers.LastActivityDate: 2018-01-19T23:03:30.563Z
Answers.UserDisplayName: Brad Bell
Body: <p>I've searched around and other solutions don't seem to be working I must be missing something obvious</p>
  
  <p>Here's what i'm doing</p>
  
  <pre><code>{% set myVar = '' %}
  {% for block in entry.matrixComponent %}
       {% if block.type == "matixBlockType" %}
            {% set myVar = block.matrixBlockField.ids() %}
       {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>This seems to work when I dump myVar I get </p>
  
  <pre><code>array(1) {
    [0]=&gt;
    string(5) "10032"
  </code></pre>
  
  <p>which is indeed the id I'm looking for. I then</p>
  
  <pre><code>{% if entry.id not in myVar %}
      &lt;div&gt; {{ entry.id }} {{ Title }} not in myVar &lt;/div&gt;
  {% else %}
      &lt;div&gt; {{ entry.id }} {{ Title }} is in myVar {{ myVar }} &lt;/div&gt;
  {% endif %}
  </code></pre>
  
  <p>It lists out my posts in the matrix component, and where the entry.id matches myVar it still says not in myVar even though it would seem to me that it should have excluded it.</p>
  
  <p>I'm not sure why it is listing the entry that matches myVar's Id</p>
  
Tags: <templating>
Title: filter entries by id retrieved from matrix block entry
ThreadText: # filter entries by id retrieved from matrix block entry
  
  (Asked by: username_0 on 2018-01-19)
  
  I've searched around and other solutions don't seem to be working I must be missing something obvious
  
  Here's what i'm doing
  
  ```
  {% set myVar = '' %}
  {% for block in entry.matrixComponent %}
       {% if block.type == "matixBlockType" %}
            {% set myVar = block.matrixBlockField.ids() %}
       {% endif %}
  {% endfor %}
  
  ```
  
  This seems to work when I dump myVar I get
  
  ```
  array(1) {
    [0]=>
    string(5) "10032"
  
  ```
  
  which is indeed the id I'm looking for. I then
  
  ```
  {% if entry.id not in myVar %}
      <div> {{ entry.id }} {{ Title }} not in myVar </div>
  {% else %}
      <div> {{ entry.id }} {{ Title }} is in myVar {{ myVar }} </div>
  {% endif %}
  
  ```
  
  It lists out my posts in the matrix component, and where the entry.id matches myVar it still says not in myVar even though it would seem to me that it should have excluded it.
  
  I'm not sure why it is listing the entry that matches myVar's Id
  
  **Tags:** templating
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-01-19. Score: 0 | Accepted answer
  
  If I do a similar test:
  
  ```
  {% set myVar = ['10032'] %}
  
  {{ dump(myVar) }}
  
  ```
  
  That gives:
  
  ```
  array (size=1)
    0 => string '10032' (length=5)
  
  ```
  
  Just like yours.
  
  ```
  {% set entryId = 10032 %}
  
  {% if entryId not in myVar %}
      {{ entryId }} not in myVar
  {% else %}
      {{ entryId }} is in myVar
  {% endif %}
  
  ```
  
  Outputs:
  
  ```
  10032 is in myVar
  
  ```
  
  As expected. Changing `entryId` to something other than 10032 gives the expected "is not in myVar".
  
  It should be noted that this line:
  
  ```
  is in myVar {{ myVar }}
  
  ```
  
  Will cause an array to string conversion error because you're telling Twig to output an array to the browser and it doesn't know how.
  
  > **Comments:**
  > **username_0**: How would I set the string to myVar instead of the whole array? at `{% set myVar = block.matrixBlockField.ids() %}`  Since I won't know the field id upfront normally. That way I can compare the strings later on.  
  > **username_0**: changing to {% if entry.id not in myVar[0] %} gets me a templating error.  
  > **username_1**: Sorry, I'm not following... in both your example and mine, `myVar` is set to an array with one string item in it set to "10032".  
  > **username_0**: It turns out that your answer correct. We had a plugin that would essentially iterate over it setting the id back to null.  
  > **username_1**: Glad you're all sorted!  
  
  ---
  
  