# Location of the Jinja Environment directory

**URL:** <https://talk.getindico.io/t/location-of-the-jinja-environment-directory/998>\
**Category:** General Discussion\
**Created:** [March 2, 2019, 6:42pm UTC](https://talk.getindico.io/t/location-of-the-jinja-environment-directory/998 "2019-03-02T18:42:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PhilippVWC](https://talk.getindico.io/user_avatar/talk.getindico.io/philippvwc/32/175_2.png) [@PhilippVWC](https://talk.getindico.io/u/PhilippVWC)\
**Post date:** [March 2, 2019, 6:42pm UTC](https://talk.getindico.io/t/location-of-the-jinja-environment-directory/998/1 "2019-03-02T18:42:11Z")

</div>

Hi,

the Jinja Template engine always requires an environment to draw the templates from. Thus an exemplified python module, whose purpose is rendering templates would start like this:

```
 from Jinja2 import Environment, FileSystemLoader
 env = Environment( loader = FileSystemLoader('templates') )
 myTemplate = env.get_template('template1.html')
 print(myTemplate.render()) ...

```

Here the **FileSystemLoader** loads a directory ‘_templates_’ relative to the location of the calling module. So I would deposit every html template (like _template1.html, template2.html_) into that directory. So this directory forms a crucial part of the Jinja environment.

If I would now import a Jinja Macro from _template1.html_ into _template2.html_ the import statement knows, where to find _template1.html_, **since the FileSystemLoader defined the location**. Namely ‘templates’. So _template2.html_ would start with:  
`{% from template1.html import macro1 %}`, where _macro1_ is a Jinja Macro defined in _template1.html_.

So now, I want to know, where this directory is located within the Indico project. I see that many templates, that import macros refer to _indico/indico/web/templates_, but some Modules like, e.g. groups ( in _indico/indico/modules_) contain html templates refering to the module groups, like e.g. _/indico/indico/modules/groups/templates/groupd\_details.html_

Cheers,

Philipp

---

<div class="post-metadata">

**Author:** ![ThiefMaster](https://talk.getindico.io/user_avatar/talk.getindico.io/thiefmaster/32/509_2.png) [@ThiefMaster](https://talk.getindico.io/u/ThiefMaster)\
**Post date:** [March 2, 2019, 7:17pm UTC](https://talk.getindico.io/t/location-of-the-jinja-environment-directory/998/2 "2019-03-02T19:17:07Z")

</div>

Hi, please explain what you are trying to do and we can give you some tips. We use some custom logic to avoid duplicating e.g. module names inside the module(blueprint)-specific template folders.

---

<div class="post-metadata">

**Author:** ![PhilippVWC](https://talk.getindico.io/user_avatar/talk.getindico.io/philippvwc/32/175_2.png) [@PhilippVWC](https://talk.getindico.io/u/PhilippVWC)\
**Post date:** [March 2, 2019, 7:36pm UTC](https://talk.getindico.io/t/location-of-the-jinja-environment-directory/998/3 "2019-03-02T19:36:57Z")

</div>

Hi ThiefMaster,

it is a question of general interest. I am learning Jinja at the moment in order to better understand the templating infrastructure of Indico. I recognized today, that Indico templates make heavy use of macros. As far as I know, a macro is imported like e.g. in  
_indico/indico/modules/events/management/templates/clone\_event.html_:

`{% from 'message_box.html' import message_box %}`, where **message\_box.html** contains the macro **message\_box**.

Now I want to know from where Jinja knows, where the template **message\_box.html** is located.

---

<div class="post-metadata">

**Author:** ![ThiefMaster](https://talk.getindico.io/user_avatar/talk.getindico.io/thiefmaster/32/509_2.png) [@ThiefMaster](https://talk.getindico.io/u/ThiefMaster)\
**Post date:** [March 2, 2019, 10:41pm UTC](https://talk.getindico.io/t/location-of-the-jinja-environment-directory/998/4 "2019-03-02T22:41:19Z")

</div>

The default template folder `indico/web/templates/` is set here:

> <https://github.com/indico/indico/blob/master/indico/web/flask/app.py#L340>

All the modules have their own blueprint, e.g. here:

> <https://github.com/indico/indico/blob/master/indico/modules/announcement/blueprint.py#L23>

By default, the [template folder](https://github.com/indico/indico/tree/master/indico/modules/announcement/templates) that belongs to the blueprint would have priority over core templates, and share the same namespace (this is a design decision in Flask that some people like and some don’t). However, in our case it’s not convenient and usually we’d have to put the templates for that blueprint inside `templates/announcement/whatever` if we wanted to render them as `'announcement/whatever'`. But repeating the module name inside the template folder is somewhat dumb, so I added some code that adds a virtual prefix for all templates in the blueprint’s template folder:

> <https://github.com/indico/indico/blob/master/indico/web/flask/wrappers.py#L206-L230>

---

<div class="post-metadata">

**Author:** ![PhilippVWC](https://talk.getindico.io/user_avatar/talk.getindico.io/philippvwc/32/175_2.png) [@PhilippVWC](https://talk.getindico.io/u/PhilippVWC)\
**Post date:** [March 5, 2019, 11:43am UTC](https://talk.getindico.io/t/location-of-the-jinja-environment-directory/998/5 "2019-03-05T11:43:27Z")

</div>

Hi Thiefmaster,

that was very clarifying. Thank you for your detailed response.  
Cheers,

Philipp
