{% if item.linksWithItems is not empty %}
    <p>Related items:</p>

    <ul>
        {% for linkWithItems in item.linksWithItems %}
            <li class="mt2">
                {% for item in linkWithItems.items %}
                    <a href="{{ path_for('singleItem', {'id': item['id']}) }}">{{ item.title }}</a>
                    {% if not loop.last %},{% endif %}
                {% endfor %}
                (connected by: <a href="{{ path_for('singleLink', {'id': linkWithItems['id']}) }}">{{ linkWithItems.title }}</a>)
            </li>
        {% endfor %}
    </ul>
{% endif %}

{% if item.linkedItems is not empty %}
    <p>Linked items:</p>

    <ul>
        {% for item in link.linkedItems %}
            <li class="mt2">
                <a href="{{ path_for('singleItem', {'id': item['id']}) }}">{{ item.title }}</a>
            </li>
        {% endfor %}
    </ul>
{% endif %}

{% if item.linksWithItems is not empty %}
    <p>Related items:</p>

    <ul>
        {% for linkWithItems in item.linksWithItems %}
            <li class="mt2">
                {% for item in linkWithItems.items %}
                    <a href="{{ path_for('singleItem', {'id': item['id']}) }}">{{ item.title }}</a>
                    {% if not loop.last %},{% endif %}
                {% endfor %}
                (connected by: <a href="{{ path_for('singleLink', {'id': linkWithItems['id']}) }}">{{ linkWithItems.title }}</a>)
            </li>
        {% endfor %}
    </ul>
{% elseif item.linkedItems is not empty %}
    <p>Linked items:</p>

    <ul>
        {% for item in link.linkedItems %}
            <li class="mt2">
                <a href="{{ path_for('singleItem', {'id': item['id']}) }}">{{ item.title }}</a>
            </li>
        {% endfor %}
    </ul>
{% else %}
    <p>This item has no relations.</p>
{% endif %}

Add text if item has no relations
Add text if item has no relations
