# Template extension order

When you extend a template using the following twig a template tree of all files, that may also extend that file will be build.

```twig
{% hw_extends 'storefront::home.twig' %}
```

Lets take for example that following module and theme extend the home template of the hostware base theme:

```
└── custom
    ├── modules
    │   └── DashservVps
    │       └── src
    │           └── resources
    │               └── views
    │                   └── home.twig
    └── themes
        └── hw
            └── horizon
                └── resources
                    └── views
                        └── home.twig
```

We can clearly see that one theme and one module tries to extend the "storefront::home.twig" template. During compilation, the following unsorted template tree gets created:

```php
array:3 [▼
  "storefront" => "C:\hostware\resources\views\storefront/home.twig"
  "dashservvps" => "C:\hostware\custom/modules/DashservVps\Resources/views/storefront/home.twig"
  "theme.horizon" => "C:\hostware\custom\themes\hw\horizon\resources\views/storefront/home.twig"
]
```

You can see the namespaces as the key and the absolute path to the template file as the value. In the next step, the hostware template finder sorts this tree in the following specific order:

1. Themes
2. Modules
3. Hostware theme

As you can see, the twig extension templates from the installed theme will be applied first. After that, any activated module with the correct file path will be considered for template building.\
Only at the end, the default hostware theme [twig blocks](https://twig.symfony.com/doc/3.x/tags/block.html) will be used.
