Organising templates in sub-folders

Helloo, I was wondering if it was possible to put templates (from site/templates) into sub folders? I’m currently coding a section for my site which has specific templates which are not used anywhere else, and I’d like to put them all in a folder inside site/templates to be more organised.

Right now I have

 templates
    ├── book.php
    ├── bookshelf.php
    ├── default.php
    ├── game.php
    ├── movie.php
[...]

I’d like to put game.php and movie.php in separate folder called rated, which is also what the section on my website is called.

├── templates
│   ├── rated
│   │   └── game.php
│   │   └── movie.php

Similarly for photography content I have special templates and I’d like to organise them all in sub-folders so the templates folder doesn’t get cluttered over time - is this possible?

Thanks in advance, and a happy new year to y’all! <3

Not really. Since which template to use is defined by the filename of the content file. And since filename cannot include slashes to mimic your nested hierarchy, it needs to be flat.

Most sites work with prefixes for these cases. rated-game.php for example.

You could potentially hack it via custom page models overwriting the template method. But that’s more advanced and you’d need a custom page model for each template. If this doesn’t immediately ring a bell and sounds easy to you, I would not consider it.

1 Like

I completely forgot to reply. Thank you. I renamed the templates as suggested and it’s easier to see what belongs “together” now!