If Conditional for Lightswitch in Matrix Field I have a section that needs to display a certain block type (heroVideo) if a lightswitch (displayHeroVideo) within it is active. Otherwise, it should display a different block type (heroImage).

How can I write a conditional to accommodate this?

Here's what I have already which outputs both blocks if the lightswitch is active. How do I apply the conditional earlier?

{# Start hero section #}
{% for entry in entry.heroFeatured.limit(1) %}
  {% for block in entry.hero %}

  {% if block.type == "heroVideo" and block.displayHeroVideo == "1" %}

  &lt;h1&gt;Hero Video Markup&lt;/h1&gt;

  {% else %}

  &lt;h1&gt;Hero Image Markup&lt;/h1&gt;

  {% endif %}
{% endfor %}
{% endfor %}
You're close! The way you have your conditional set up now will print Hero Image Markup if either of your conditionals fail. By checking if block.displayHeroVideo is 1 on a block type that doesn't have that field, Twig will still return 0. You should only check displayHeroVideo when you know you are inside of a heroVideo block. 

{% for entry in entry.heroFeatured.limit(1) %}
    {% for block in entry.hero %}

        {% if block.type == "heroVideo" %}

            {% if block.displayHeroVideo == "1" %} 

                &lt;h1&gt;Hero Video Markup&lt;/h1&gt;

            {% endif %}

        {% else %}

            &lt;h1&gt;Hero Image Markup&lt;/h1&gt;

        {% endif %}
    {% endfor %}
{% endfor %}