Answers.Body: <p>Try something like:</p>
  
  <pre><code>{% for block in entry.information %}
  {% if block.type == "images" %}
      {% set image = block.image.first() %}
          {% if image %}
              {% if block.anchor |length %}
              &lt;a href={{ block.anchor | cacheBuster }} target="_blank"&gt;
                  &lt;img class="slideshow" src={{ image.url | cacheBuster }} alt={{ image.title }}&gt;
              &lt;/a&gt;
              {% else %}
              &lt;img class="slideshow" src={{ image.url | cacheBuster }} alt={{ image.title }}&gt;
              {% endif %}
          {% endif %}
      {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>So that only if the <code>block.anchor</code> field has something in it do you generate the link &amp; the image. Otherwise, you just generate the image.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-21T06:57:57.060Z
Answers.LastActivityDate: 2017-02-21T06:57:57.060Z
Answers.UserDisplayName: andrew.welch
Body: <p>So I am using the matrix field to enable uploading of images onto a slideshow for the homepage section. My goal is to have one of the images link to another URL when you click on it. Basic stuff when using plain HTML, but I have it setup like this in Twig:</p>
  
  <pre><code>{% for block in entry.information %}
  {% if block.type == "images" %}
     {% set image = block.image.first() %}
         {% if image %}
              &lt;a href={{ block.anchor | cacheBuster }} target="_blank"&gt;
                  &lt;img class="slideshow" src={{ image.url | cacheBuster }} alt={{ image.title }}&gt;
              &lt;/a&gt;
          {% endif %}
      {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>This code runs fine and my slideshow images are all displayed using just one loop.</p>
  
  <p>The problem is, all my slides are having an anchor field activated. I only want one of the slides to have a link to a URL, however, in the future I may want to add links to other slides so I need something that is also dynamic enough to support this.</p>
  
  <p>My whole entire approach may be wrong and I might need to use a completely different approach... assistance is greatly appreciated.</p>
  
Tags: <templating>
Title: How to assign a URL to only one slide in a template using Matrix?
ThreadText: # How to assign a URL to only one slide in a template using Matrix?
  
  (Asked by: username_0 on 2017-02-21)
  
  So I am using the matrix field to enable uploading of images onto a slideshow for the homepage section. My goal is to have one of the images link to another URL when you click on it. Basic stuff when using plain HTML, but I have it setup like this in Twig:
  
  ```
  {% for block in entry.information %}
  {% if block.type == "images" %}
     {% set image = block.image.first() %}
         {% if image %}
              <a href={{ block.anchor | cacheBuster }} target="_blank">
                  <img class="slideshow" src={{ image.url | cacheBuster }} alt={{ image.title }}>
              </a>
          {% endif %}
      {% endif %}
  {% endfor %}
  
  ```
  
  This code runs fine and my slideshow images are all displayed using just one loop.
  
  The problem is, all my slides are having an anchor field activated. I only want one of the slides to have a link to a URL, however, in the future I may want to add links to other slides so I need something that is also dynamic enough to support this.
  
  My whole entire approach may be wrong and I might need to use a completely different approach... assistance is greatly appreciated.
  
  **Tags:** templating
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-02-21. Score: 3
  
  Try something like:
  
  ```
  {% for block in entry.information %}
  {% if block.type == "images" %}
      {% set image = block.image.first() %}
          {% if image %}
              {% if block.anchor |length %}
              <a href={{ block.anchor | cacheBuster }} target="_blank">
                  <img class="slideshow" src={{ image.url | cacheBuster }} alt={{ image.title }}>
              </a>
              {% else %}
              <img class="slideshow" src={{ image.url | cacheBuster }} alt={{ image.title }}>
              {% endif %}
          {% endif %}
      {% endif %}
  {% endfor %}
  
  ```
  
  So that only if the `block.anchor` field has something in it do you generate the link & the image. Otherwise, you just generate the image.
  
  
  ---
  
  