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 %}
<a href="{{ entry.cpEditUrl }}" target="_blank" id="editEntry" class="cta">Edit this entry</a>
{% 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 %}
<a href="{{ entry.cpEditUrl }}" target="_blank" id="editEntry" class="cta">Edit this entry</a>
{% endif %}
{% endif %}
{% endif %}