Body: <p>I have an entry with matrix fields. If I add blocks in the main language, but its fields only contain data in one language, the block query (the for loop) still finds these empty fields since they do contain data in the other language. It is easy not to display the fields and their enclosing divs with an if statement.</p>
  <p>However, if all the fields are empty, I don't even want to display the enclosing/parent div/title of all the blocks; and also do not want it to show on the page menu. I could loop through all of the blocks each time to find out if all the fields are empty — and then not display the enclosing title – but is there an easier way?</p>
  <pre><code>{% set referenceBlocks = entry.references.all() %} 
  {% if referenceBlocks|length %}
      &lt;div class=&quot;parent&quot;&gt;
          &lt;div class=&quot;showMobile&quot;&gt;&lt;h3 class=&quot;title&quot;&gt;{{ &quot;References&quot;|t }}&lt;/h3&gt;&lt;/div&gt;
  
              {% for block in referenceBlocks %}
                  {% if block.referenceLink|length or block.referenceText|length or block.referenceSource|length %}
                      &lt;div class=&quot;w-full&quot;&gt;
                      {% if block.referenceLink|length %}
                          &lt;a target=&quot;_blank&quot; href=&quot;{{ block.referenceLink|default }}&quot;&gt;
                      {% endif %}
                      &lt;p&gt;
                          {{ block.referenceText }}
                          &lt;span class=&quot;text-sm italic&quot;&gt;{{ block.referenceSource }}&lt;/span&gt;
                      &lt;/p&gt;
                      {{ block.referenceLink|length ? &quot;&lt;/a&gt;&quot; }}
                      {% endif %}
                      &lt;/div&gt;
                  {% endif %}
              {% endfor %}
          &lt;/div&gt;
      &lt;/div&gt;
  {% endif %}
  </code></pre>
  <p>So I don't want to show the elements outside the for loop if all the blocks and fields in those blocks are empty. The first if statement only works when there are no matrix block in ALL languages, but when there are some in the main language but not in the other one, it will display the parent div and title.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-01-07T07:26:37.283Z
Comments.Text: Could you share some of your code?
Comments.UserDisplayName: Oli
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-01-07T07:47:07.020Z
Comments.Text: I added some code
Comments.UserDisplayName: Matthias
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-01-07T08:16:10.867Z
Comments.Text: I'm not seeing the thing as you. For me, your code works and hides. What **Propagation Method** do you have on your Matrix field? Also, is `entry` the default auto-injected `entry` variable on an entry page?
Comments.UserDisplayName: Oli
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-01-07T08:59:38.573Z
Comments.Text: I have a feeling you are not using _Only save blocks to the site they were created in_ as your **Propagation Method**.
Comments.UserDisplayName: Oli
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-01-09T07:04:47.670Z
Comments.Text: Thanks for reminding me of the propagation methods. I have fields with different methods. I prefer consistency for all matrix fields for our users. I don't want to use *Only save blocks to the site they were created in* in most of the cases, but I may use them for some matrix fields. 
  
  However, also deleting matrix entries behave differently; with this option they only get deleted in the current language, but with the other option, they get deleted in all the other sites as well. A bit confusing for our users, but I can add a description to the fields that behave differently.
Comments.UserDisplayName: Matthias
Tags: <matrix><query>
Title: Hiding enclosing div if all matrix block fields are empty (although they do exist because of another language)
ThreadText: # Hiding enclosing div if all matrix block fields are empty (although they do exist because of another language)
  
  (Asked by: username_0 on 2021-01-06)
  
  I have an entry with matrix fields. If I add blocks in the main language, but its fields only contain data in one language, the block query (the for loop) still finds these empty fields since they do contain data in the other language. It is easy not to display the fields and their enclosing divs with an if statement.
  
  However, if all the fields are empty, I don't even want to display the enclosing/parent div/title of all the blocks; and also do not want it to show on the page menu. I could loop through all of the blocks each time to find out if all the fields are empty — and then not display the enclosing title – but is there an easier way?
  
  ```
  {% set referenceBlocks = entry.references.all() %} 
  {% if referenceBlocks|length %}
      <div class="parent">
          <div class="showMobile"><h3 class="title">{{ "References"|t }}</h3></div>
  
              {% for block in referenceBlocks %}
                  {% if block.referenceLink|length or block.referenceText|length or block.referenceSource|length %}
                      <div class="w-full">
                      {% if block.referenceLink|length %}
                          <a target="_blank" href="{{ block.referenceLink|default }}">
                      {% endif %}
                      <p>
                          {{ block.referenceText }}
                          <span class="text-sm italic">{{ block.referenceSource }}</span>
                      </p>
                      {{ block.referenceLink|length ? "</a>" }}
                      {% endif %}
                      </div>
                  {% endif %}
              {% endfor %}
          </div>
      </div>
  {% endif %}
  
  ```
  
  So I don't want to show the elements outside the for loop if all the blocks and fields in those blocks are empty. The first if statement only works when there are no matrix block in ALL languages, but when there are some in the main language but not in the other one, it will display the parent div and title.
  
  **Tags:** matrix, query
  
  > **Comments:**
  > **username_1**: Could you share some of your code?  
  > **username_0**: I added some code  
  > **username_1**: I'm not seeing the thing as you. For me, your code works and hides. What **Propagation Method** do you have on your Matrix field? Also, is `entry` the default auto-injected `entry` variable on an entry page?  
  > **username_1**: I have a feeling you are not using _Only save blocks to the site they were created in_ as your **Propagation Method**.  
  > **username_0**: Thanks for reminding me of the propagation methods. I have fields with different methods. I prefer consistency for all matrix fields for our users. I don't want to use *Only save blocks to the site they were created in* in most of the cases, but I may use them for some matrix fields.   However, also deleting matrix entries behave differently; with this option they only get deleted in the current language, but with the other option, they get deleted in all the other sites as well. A bit confusing for our users, but I can add a description to the fields that behave differently.  
  
  ---
  
  ## 0 answers
  
  