Parent templates access to child template context

I’ve implemented a standard template structure with base.html calling various templates. My Django app generates code for the ‘services’ block within base.html. Also in base.html there is an ‘aboutus’ block which is at the same level as my services block. Is it possible to use template variables sent to the services block within the aboutus block? Ideally I don’t want to create a new app for aboutus just to send one variable to it’s template.

A template does not “call” another template. A template may include one or more other templates - is that what you’re referring to here?

See the docs for the include tag for all the details about what this means.

Also, I’m not sure I understand what you mean by:

A block in a base template is a placeholder for a location on a page that is generally intended to be filled by the template that extends it.

In other words, you may have a block named “myblock” in the base template. Your templates being rendered can use the “extends” tag, and supply html to replace (or add to) that block in the parent template.

See the docs for Template inheritance for more details about how to use this.

If you’re having a specific issue where you would like a more detailed explanation, please provide a minimal example template that demonstrates what it is you are trying to do. It may be a lot more meaningful to you if we had a tangible example to work from.

So a cut down base.html looks like:

{% load static %}
<!DOCTYPE html>
<html lang="en" dir="">

<head>
</head>

    {% block navbar %}
        {% include 'partials/navbar.html' %}
    {% endblock navbar %}

    {% block home %}
    {% endblock home %} 

    {% block services %}
    {% endblock services %}
    
    {% block aboutus %}
        {% include 'partials/aboutus.html' %}
    {% endblock aboutus %}

    {% block contactForm %}
        {% include 'partials/contactForm.html' %}
    {% endblock contactForm %}

    {% block footer %}
        {% include 'partials/footer.html' %}
    {% endblock footer %}
</body>

</html>

My app creates html to go into the services block. What I want to do is make available to the aboutus block a value that is currently available in the services block. The aboutus template cut down looks like:

{% load static %}

{% block aboutus %}   

    <!--END ABOUT US-->
...
                       <!-- I would like to pass demo_asc_id to here from my app -->
                        <a href="{% url 'showorderofplay:association-index' {{demo_asc_id}} %}" class="btn btn-primary mt-4 ">Give the Demo a go <i class="mdi mdi-arrow-right"></i></a>
                    
{% endblock aboutus %}

So far I have used url.py to call views.py / forms.py to generate html via a template.html. Do I have to split aboutus.html so that my app can generate that url line in a template and then within the template do {% include aboutus.html %} ? I already have the url defined which calls my app so I’m not clear how I can generate two different templates from the same url i.e. have two views each building there respective templates?

You need to shift your perspective on this. Templates do not “do” anything.

Most importantly, a template does not call a view to be executed. That’s the wrong perspective to be thinking about this. A view can render as many templates as it wants, but it’s still only one view that is going to be executed for a page.

In a view, you’re calling one of the rendering functions that reads a template and renders it, using the supplied context as the data elements to be rendered in variables in that template.

All templates being rendered share the same context, unless you use one of the directives that override it. (e.g., the “only” option on an include tag.)

So, in your example, you’re referencing a variable named

in your context to this template.

That variable is going to be available in all included templates when you’re rendering it.