2

I am getting this error returned whilst in Debug mode:

Template Error

Impossible to access an attribute ("gatewayHandle") on a NULL variable ("")

Not sure why this is getting flagged up. It is a variable which is accessed through the Dukt Video plugin? Seems to work when not in debug mode, but I am getting slow initial response times when loading, not sure if this is related to that issue.

I have attached the relevant page code:

{# Video Link :: if entry is of video type #}

{% if entries.section == "Videos" %}

    {% set video = entries.video %}

    {% if video.gatewayHandle == 'youtube' %}
        <a
            data-target="flare"
            href="http://youtu.be/{{ video.id }}"
        >
    {% else %}
        <a
            data-target="flare"
            href="http://vimeo.com/{{ video.id }}"
        >
    {% endif %}

{% else %}

{# Entry link #}

<a href="{{ entries.url }}">

Any help would be appreciated.

1
  • Hi Daryl, looks like you accidentally posted this in the "Meta" section... I'll go ahead and move it back to the main Stack Exchange site for you. – Lindsey D Feb 2 '15 at 22:28
2

That message is telling you that gatewayHandle can't be accessed from video, because video is NULL. You're expecting the videos field to always contain an object, but in this case it is not.

I would suggest that you ensure that video actually contains a value before you attempt to reference one of its properties...

{% set video = entries.video %}

{% if video %}

    {% if video.gatewayHandle == 'youtube' %}
        ...
    {% endif %}

{% endif %}
2
  • wouldn't it be: {% set video = entries.video.first %}? – Marion Newlevant Feb 3 '15 at 22:24
  • Could be, that's probably why it's returning NULL. I didn't think much about his data structure, just simply telling him what that error meant, and how to protect against it. – Lindsey D Feb 3 '15 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.