'What makes bootstrap badge not showing in condition?

In my base template: base.html.twig, i have

{% if app.user.getReceivedMessage | length > 0 %}
    {% set urm = 0 %}
    {% for msg in app.user.getReceivedMessage %}
        {% if not msg.getIsRead %}
            {% set urm = urm + 1 %}
        {% endif %}
    {% endfor %}
{% endif %}
{% if urm is defined %}
    <span class="position-absolute top-75 end-15 translate-middle p-1-5 bg-danger rounded-circle">
        <span class="visually-hidden">New alerts</span> // The badge appears here.
    </span>
{% endif %}

Now in the index.html.twig

{% extends 'base.html.twig' %}
// code lines
{% if urm is defined %}
    Inbox    
    <span class="badge bg-danger ms-3">{{ 0 }}</span> // Not printed, seems urm is not set
{% endif %}
// Somewhere down
{% include 'inbox.html.twig' %}

But in the inbox.html.twig i have

        {% if urm is defined %} // all this is printed so urm is defined here
            <div class="col-sm-12 col-md-6">
                <h3 class="font-light mb-0">
                    <i class="fas fa-email mr-2"></i>
                    {{ urm }}
                    New messages</h3>
            </div>
        {% endif %}

The urm is defined in the base template, not defined in the index but defined in the inbox(who is inside the index). Really confused

How can i solve this issue please?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source