<p>It's not exactly "quick", you'll have to do something like this:</p>

<pre><code>{% if socialNetworkContent.branchFacebookProfile|length 
       or socialNetworkContent.branchTwitterAccount|length
       or socialNetworkContent.branchLinkedInAccount|length
       ...
%}
</code></pre>

<p>Which is probably exactly what you're trying to avoid.</p>

<p>If you want to just make it a little easier to read, you can do something like this:</p>

<pre><code>{% set x = socialNetworkContent %}

{% if x.branchFacebookProfile|length 
       or x.branchTwitterAccount|length
       or x.branchLinkedInAccount|length
       ...
%}
</code></pre>

<p>The hurdle that you're dealing with is the fact that the <code>socialNetworkContent</code> object contains many other attributes besides just your custom field names. So there's not really any efficient way to "loop through" your custom fields without dealing with a bunch of extra junk.</p>

<p>Of course, you could build a plugin to create a simple boolean variable, but that sounds like overkill for this situation.</p>

CC BY-SA 3.0
2014-09-05T19:58:32.477Z
2014-09-05T19:58:32.477Z
Lindsey D
<p>I have a global set called socialNetworkContent.</p>

<p>Is there a way to setup a conditional to check whether any of the fields within this set have content?</p>

<p>So the section wouldn't display if all the fields were blank.</p>

<p>Something along these lines:</p>

<pre><code>{% if socialNetworkContent|length %}
&lt;section&gt;
&lt;div class="social"&gt;
    &lt;h1&gt;Follow Us&lt;/h1&gt;
    &lt;ul&gt;
            {% if socialNetworkContent.branchFacebookProfile|length %}&lt;li&gt;&lt;a href="{{ socialNetworkContent.branchFacebookProfile }}"&gt;&lt;i class="fa fa-facebook fa-2x"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;{% endif %}
            {% if socialNetworkContent.branchTwitterAccount|length %}&lt;li&gt;&lt;a href="{{ socialNetworkContent.branchTwitterAccount }}"&gt;&lt;i class="fa fa-twitter fa-2x"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;{% endif %}
            {% if socialNetworkContent.branchLinkedInAccount|length %}&lt;li&gt;&lt;a href="{{ socialNetworkContent.branchLinkedInAccount }}"&gt;&lt;i class="fa fa-linkedin fa-2x"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;{% endif %}
            {% if socialNetworkContent.branchGooglePlusAccount|length %}&lt;li&gt;&lt;a href="{{ socialNetworkContent.branchGooglePlusAccount }}"&gt;&lt;i class="fa fa-google-plus fa-2x"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;{% endif %}
            {% if socialNetworkContent.branchInstagramAccount|length %}&lt;li&gt;&lt;a href="{{ socialNetworkContent.branchInstagramAccount }}"&gt;&lt;i class="fa fa-instagram fa-2x"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;{% endif %}
            {% if socialNetworkContent.branchYoutubeAccount|length %}&lt;li&gt;&lt;a href="{{ socialNetworkContent.branchYoutubeAccount }}"&gt;&lt;i class="fa fa-youtube fa-2x"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;{% endif %}
    &lt;/ul&gt;
&lt;/div&gt;
&lt;/section&gt;
{% endif %}
</code></pre>

<conditional>
Is there a way to check if any fields in a global set have content?
# Is there a way to check if any fields in a global set have content?

(Asked by: username_0 on 2014-09-05)

I have a global set called socialNetworkContent.
Is there a way to setup a conditional to check whether any of the fields within this set have content?
So the section wouldn't display if all the fields were blank.
Something along these lines:
{% if socialNetworkContent|length %}


    Follow Us
    
            {% if socialNetworkContent.branchFacebookProfile|length %}{% endif %}
            {% if socialNetworkContent.branchTwitterAccount|length %}{% endif %}
            {% if socialNetworkContent.branchLinkedInAccount|length %}{% endif %}
            {% if socialNetworkContent.branchGooglePlusAccount|length %}{% endif %}
            {% if socialNetworkContent.branchInstagramAccount|length %}{% endif %}
            {% if socialNetworkContent.branchYoutubeAccount|length %}{% endif %}
    


{% endif %}

**Tags:** conditional


---

## 1 answers

### Answer by username_1 on 2014-09-05. Score: 2 | Accepted answer

It's not exactly "quick", you'll have to do something like this:
{% if socialNetworkContent.branchFacebookProfile|length 
       or socialNetworkContent.branchTwitterAccount|length
       or socialNetworkContent.branchLinkedInAccount|length
       ...
%}

Which is probably exactly what you're trying to avoid.
If you want to just make it a little easier to read, you can do something like this:
{% set x = socialNetworkContent %}

{% if x.branchFacebookProfile|length 
       or x.branchTwitterAccount|length
       or x.branchLinkedInAccount|length
       ...
%}

The hurdle that you're dealing with is the fact that the socialNetworkContent object contains many other attributes besides just your custom field names. So there's not really any efficient way to "loop through" your custom fields without dealing with a bunch of extra junk.
Of course, you could build a plugin to create a simple boolean variable, but that sounds like overkill for this situation.


---

