Answers.Body: <p>You can just test if image is defined first using:</p>
  
  <pre><code>{% set image = block.image.first() %}
  {% if image %}
      &lt;a href="{{ image.getUrl() }}"&gt;...&lt;/a&gt;
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-15T00:55:13.810Z
Answers.LastActivityDate: 2017-07-23T17:06:24.697Z
Answers.LastEditDate: 2017-07-23T17:06:24.697Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>This was working fine previously and not sure what triggered the error. Any idea how to resolve issue?</p>
  
  <pre><code>{% for block in entry.servicesItems.type('images') %}
      &lt;div class="col"&gt;
  
          {# grab the first image #}
          {% set image = block.image.first() %}
  
          {# link to the full sized version #}
              &lt;a href="{{ image.getUrl }}"&gt;
          {# generated the transformed thumbnail version #}
              &lt;img src="{{ image.getUrl('servicesImageCrop')}}" alt="{{ block.alt }}" width="{{ image.getWidth('servicesImageCrop') }}" height="{{ image.getHeight('servicesImageCrop') }}"&gt;
              &lt;div id="lightbox-title"&gt;
                  &lt;h2&gt;{{ block.imageTitle }}&lt;/h2&gt;
                  &lt;p&gt;{{ block.imageContent }}&lt;/p&gt;
              &lt;/div&gt;
          &lt;/a&gt;
      &lt;/div&gt;
  {% endfor %}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-13T21:25:21.337Z
Comments.Text: Figured it out, it was actually caused by an empty matrix block in an entry. Any idea how to prevent this from page error if user accidentally does this?
Comments.UserDisplayName: frshjb373
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-13T21:56:35.647Z
Comments.Text: You can check if it is defined first using `{% if block.image.first() %}...{% endif %}` or `{% if image %}...{% endif %}`.
Comments.UserDisplayName: Douglas McDonald
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-13T23:28:05.510Z
Comments.Text: Can you add that as an official answer, @frshjb373?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-15T18:18:51.817Z
Comments.Text: If you found an answer to your question, you can post it :) Answering own questions is not discouraged.
Comments.UserDisplayName: nicael
Tags: <templating><matrix><image>
Title: Getting error in template: Impossible to access an attribute ("getUrl") on a NULL variable ("")
ThreadText: # Getting error in template: Impossible to access an attribute ("getUrl") on a NULL variable ("")
  
  (Asked by: username_0 on 2014-11-13)
  
  This was working fine previously and not sure what triggered the error. Any idea how to resolve issue?
  
  ```
  {% for block in entry.servicesItems.type('images') %}
      <div class="col">
  
          {# grab the first image #}
          {% set image = block.image.first() %}
  
          {# link to the full sized version #}
              <a href="{{ image.getUrl }}">
          {# generated the transformed thumbnail version #}
              <img src="{{ image.getUrl('servicesImageCrop')}}" alt="{{ block.alt }}" width="{{ image.getWidth('servicesImageCrop') }}" height="{{ image.getHeight('servicesImageCrop') }}">
              <div id="lightbox-title">
                  <h2>{{ block.imageTitle }}</h2>
                  <p>{{ block.imageContent }}</p>
              </div>
          </a>
      </div>
  {% endfor %}
  
  ```
  
  **Tags:** templating, matrix, image
  
  > **Comments:**
  > **username_0**: Figured it out, it was actually caused by an empty matrix block in an entry. Any idea how to prevent this from page error if user accidentally does this?  
  > **username_1**: You can check if it is defined first using `{% if block.image.first() %}...{% endif %}` or `{% if image %}...{% endif %}`.  
  > **username_2**: Can you add that as an official answer, @username_0?  
  > **username_3**: If you found an answer to your question, you can post it :) Answering own questions is not discouraged.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-12-15. Score: 2 | Accepted answer
  
  You can just test if image is defined first using:
  
  ```
  {% set image = block.image.first() %}
  {% if image %}
      <a href="{{ image.getUrl() }}">...</a>
  {% endif %}
  
  ```
  
  
  ---
  
  