1

I have an entry that needs to be disabled until the content is finalized. I am not able to 'preview' the entry unless I enable it. If I remove the navigation code, 'preview' will work on the disabled entry. Any ideas on why this is happening? The Twig Error I am getting is Impossible to access an attribute("registerLink") on a null variable.

Twig Error Image

Here is our navigation code:

{% extends '_layouts/main' %}

{% block main %}

{% set mainEntry = craft.entries.slug(craft.app.request.getSegment(1)).one() %}
{% set academyLink = craft.entries.descendantOf(mainEntry).slug('academy').one() %}
{% set navLink = craft.entries.descendantOf(mainEntry).mainLevelNavigation('1').all() %}
{% set registerLink = mainEntry.registerLink %}
{% set subnav = craft.entries.descendantOf(mainEntry).secondLevelNavigation('1').all() %}
{% set subnav2 = craft.entries.descendantOf(academyLink).level(3).all() %}

<nav class="navbar navbar-expand-lg main-menu">
    <div class="standard-wrapper">
        <div class="navbar-brand logo logo-white visible"><a href="#"><img src="{{siteUrl}}images/logos/UUGC_2019_year-logo_W.png"/></a></div>
        <!--<div class="navbar-brand logo logo-black hidden"><a href="#"><img src="{{siteUrl}}images/logos/unite-generic-black-1.png"/></a></div>-->
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation" onclick="myFunction(this)">
            <span class="navbar-toggler-icon">
            <div class="bar1"></div>
            <div class="bar2"></div>
            <div class="bar3"></div></span>
        </button>

        <div class="collapse navbar-collapse float-right menu" id="navbarSupportedContent">
            <ul class="navbar-nav mr-auto no-list-style">
                <li class="nav-item active">
                    <a class="" href="{{mainEntry.getUrl}}">Home</a>
                </li>
                <li class="nav-item dropdown">
                    <a class="dropdown-toggle" href="javascript:void(0);" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        Conference
                    </a><i class="dropdown-toggle fa fa-chevron-down" data-toggle="dropdown"></i>
                    <div class="dropdown-menu sub-menu" aria-labelledby="navbarDropdown">
                        <ul class="no-list-style">
                            {% for page in subnav %}
                            <li class="nav-item">
                                {{ page.link }}
                            </li>
                            {% endfor %}
                        </ul>
                    </div>
                </li>
                {% if academyLink|length %}
                <li class="nav-item dropdown"><a class="dropdown-toggle" href="{{academyLink.getUrl}}" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{academyLink}}</a><i class="dropdown-toggle fa fa-chevron-down" data-toggle="dropdown"></i>
                    <div class="dropdown-menu sub-menu" aria-labelledby="navbarDropdown">
                        <ul class="no-list-style">
                            {% for page in subnav2 %}
                            <li class="nav-item">
                                {{ page.link }}
                            </li>
                            {% endfor %}
                        </ul>
                    </div>
                </li>
                {% endif %}
                {% for page in navLink %}
                    <li class="nav-item">
                        {{ page.link }}
                    </li>
                {% endfor %}
                {% if registerLink|length %}
                <li class="nav-item"><a class="nav-link" href="{{registerLink}}">REGISTER</a></li>
                {% endif %}
            </ul>
        </div>
    </div>
</nav>

{% include "conferences/_types/" ~ entry.type %}

{% endblock %}
1

Added a conditional to remove navigation if mainEntry is disabled.

{% extends '_layouts/main' %}

{% block main %}

{% set mainEntry = craft.entries.slug(craft.app.request.getSegment(1)).one() %}

{% if mainEntry %}  
{% set academyLink = craft.entries.descendantOf(mainEntry).slug('academy').one() %}
{% set navLink = craft.entries.descendantOf(mainEntry).mainLevelNavigation('1').all() %}
{% set registerLink = mainEntry.registerLink %}
{% set subnav = craft.entries.descendantOf(mainEntry).secondLevelNavigation('1').all() %}
{% set subnav2 = craft.entries.descendantOf(academyLink).level(3).all() %}


<nav class="navbar navbar-expand-lg main-menu">
    <div class="standard-wrapper">
        <div class="navbar-brand logo logo-white visible"><a href="https://conference.ungerboeck.com"><img src="{{siteUrl}}images/logos/UUGC_2019_year-logo_W.png"/></a></div>
        <!--<div class="navbar-brand logo logo-black hidden"><a href="https://conference.ungerboeck.com"><img src="{{siteUrl}}images/logos/unite-generic-black-1.png"/></a></div>-->
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation" onclick="myFunction(this)">
            <span class="navbar-toggler-icon">
            <div class="bar1"></div>
            <div class="bar2"></div>
            <div class="bar3"></div></span>
        </button>

        <div class="collapse navbar-collapse float-right menu" id="navbarSupportedContent">
            <ul class="navbar-nav mr-auto no-list-style">
                <li class="nav-item active">
                    <a class="" href="{{mainEntry.getUrl()}}">Home</a>
                </li>
                <li class="nav-item dropdown">
                    <a class="dropdown-toggle" href="javascript:void(0);" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        Conference
                    </a><i class="dropdown-toggle fa fa-chevron-down" data-toggle="dropdown"></i>
                    <div class="dropdown-menu sub-menu" aria-labelledby="navbarDropdown">
                        <ul class="no-list-style">
                            {% for page in subnav %}
                            <li class="nav-item">
                                {{ page.link }}
                            </li>
                            {% endfor %}
                        </ul>
                    </div>
                </li>
                {% if academyLink|length %}
                <li class="nav-item dropdown"><a class="dropdown-toggle" href="{{academyLink.getUrl}}" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{academyLink}}</a><i class="dropdown-toggle fa fa-chevron-down" data-toggle="dropdown"></i>
                    <div class="dropdown-menu sub-menu" aria-labelledby="navbarDropdown">
                        <ul class="no-list-style">
                            {% for page in subnav2 %}
                            <li class="nav-item">
                                {{ page.link }}
                            </li>
                            {% endfor %}
                        </ul>
                    </div>
                </li>
                {% endif %}
                {% for page in navLink %}
                    <li class="nav-item">
                        {{ page.link }}
                    </li>
                {% endfor %}
                {% if registerLink|length %}
                <li class="nav-item"><a class="nav-link" href="{{registerLink}}">REGISTER</a></li>
                {% endif %}
            </ul>
        </div>
    </div>
</nav>

{% endif %}

{% include "conferences/_types/" ~ entry.type %}

{% endblock %}

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.