How to setup conditionals within a matrix? In my matrix field, I want to be able to upload my image, and then upload another asset (in this case it would be a document) so that that image I upload links to that document.

I have my Matrix field setup like so:

Image ->
  -Image
  -linkedDocument

How can I set up a conditional where only add in the  tag if I add an asset there?

Here is my relevant code:

% elseif block.type == "image" %}

        {% set image = block.image.first() %}

        {% if image %}
            &lt;a href="{{ image.linkedDocument }}"&gt;&lt;img src="{{ image.getUrl('thumb') }}" width="{{ image.getWidth('thumb') }}" height="{{ image.getHeight('thumb') }}" alt="{{ image.title }}"&gt;&lt;/a&gt;
            {% endif %}
        {% endif %}
If you have an image, you want to display it, and if there is also a linkedDocument, you want the image to link to that document. This should handle both cases, without too much code duplication.

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

  {% set image = block.image.first %}

  {% if image %}
    {# set the imgTag, which we will display regardless #}
    {% set imgTag %}
      &lt;img src="{{ image.getUrl('thumb') }}" width="{{ image.getWidth('thumb') }}"  height="{{ image.getHeight('thumb') }}" alt="{{ image.title }}"&gt;&lt;/a&gt; alt="{{ image.title }}"&gt;
    {% endset %}

    {% set linkedDocument = block.linkedDocument.first %}

    {# we may or may not have a linkedDocument. Display the image in either case #}
    {% if linkedDocument %}
      &lt;a href="{{ linkedDocument.url }}"&gt;{{imgTag}}&lt;/a&gt;
    {% else %}
      {{imgTag}}
    {% endif %}
  {% endif %}

{% endif %}