<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>

CC BY-SA 4.0
2021-01-07T07:26:37.283Z
Could you share some of your code?
Oli
CC BY-SA 4.0
2021-01-07T07:47:07.020Z
I added some code
Matthias
CC BY-SA 4.0
2021-01-07T08:16:10.867Z
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?
Oli
CC BY-SA 4.0
2021-01-07T08:59:38.573Z
I have a feeling you are not using _Only save blocks to the site they were created in_ as your **Propagation Method**.
Oli
CC BY-SA 4.0
2021-01-09T07:04:47.670Z
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.
Matthias
<matrix><query>
Hiding enclosing div if all matrix block fields are empty (although they do exist because of another language)
# 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 %}
    
        {{ "References"|t }}

            {% for block in referenceBlocks %}
                {% if block.referenceLink|length or block.referenceText|length or block.referenceSource|length %}
                    
                    {% if block.referenceLink|length %}
                        
                    {% endif %}
                    
                        {{ block.referenceText }}
                        {{ block.referenceSource }}
                    
                    {{ block.referenceLink|length ? "" }}
                    {% endif %}
                    
                {% endif %}
            {% endfor %}
        
    
{% 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

