<p>You could combine the first three:</p>

<p><code>{% if entry is defined and entry and entry.isEditable %}</code></p>

<p>If the first or second part of this logic fails, it will not check the third part so no error will be thrown. The second part is for the rare cases that a variable with the name <code>entry</code> exists but is null.</p>

<p>If entry is defined, it's always an entry (or at least it should be), so you don't have to check if isEditable is defined.</p>

CC BY-SA 3.0
2014-10-06T13:29:54.900Z
2014-10-06T13:29:54.900Z
Paul
<p>I've had this issue a few times &amp; wanted to know if there is maybe a better way to deal with the following issue:</p>

<p>Say I have this if on a page:</p>

<pre><code>{% if entry.isEditable %}
    &lt;a href="{{ entry.cpEditUrl }}" target="_blank" id="editEntry" class="cta"&gt;Edit this entry&lt;/a&gt;
{% endif %}
</code></pre>

<p>On an editable entry, the button appears if logged in. If logged out the button does not appear.</p>

<p>If I visit a page that is not an entry (just a template group) when logged in or not, I get this error:</p>

<pre><code>Impossible to access an attribute ("isEditable") on a NULL variable ("")
</code></pre>

<p>The only successful way I've seen to so far to make this behave is as follows:</p>

<pre><code>{% if entry is defined %}
    {% if entry.isEditable is defined %}
        {% if entry.isEditable %}
            &lt;a href="{{ entry.cpEditUrl }}" target="_blank" id="editEntry" class="cta"&gt;Edit this entry&lt;/a&gt;
        {% endif %}
    {% endif %}
{% endif %}
</code></pre>

<entry><variable><null><defined>
Best way to deal with Impossible to access an attribute ("isEditable") on a NULL variable ("")
# Best way to deal with Impossible to access an attribute ("isEditable") on a NULL variable ("")

(Asked by: username_0 on 2014-10-06)

I've had this issue a few times & wanted to know if there is maybe a better way to deal with the following issue:
Say I have this if on a page:
{% if entry.isEditable %}
    Edit this entry
{% endif %}

On an editable entry, the button appears if logged in. If logged out the button does not appear.
If I visit a page that is not an entry (just a template group) when logged in or not, I get this error:
Impossible to access an attribute ("isEditable") on a NULL variable ("")

The only successful way I've seen to so far to make this behave is as follows:
{% if entry is defined %}
    {% if entry.isEditable is defined %}
        {% if entry.isEditable %}
            Edit this entry
        {% endif %}
    {% endif %}
{% endif %}

**Tags:** entry, variable, null, defined

---

## 1 answers

### Answer by username_1 on 2014-10-06. Score: 5 | Accepted answer

You could combine the first three:

`{% if entry is defined and entry and entry.isEditable %}`

If the first or second part of this logic fails, it will not check the third part so no error will be thrown. The second part is for the rare cases that a variable with the name `entry` exists but is null.

If entry is defined, it's always an entry (or at least it should be), so you don't have to check if isEditable is defined.


---

