Template sub-folders

Is it still impossible to group templates into subfolders? At least without major hacks?

No, organizing templates in folders is not possible, unless you register them in a plugin.

For example, create a file tpl.php in /site/plugins/tpl with the following content:

<?php
$kirby->set('template',     'blog',     kirby()->roots()->templates() . '/blog/blog.php');

And so on. This would allow you to store your blog template in a blog subfolder in /site/templates/-

Damn, was afraid of that. Have to try a file prefix naming.

Do you have many page types that request different templates? Big sites I’ve worked on use 20-30, that’s still a manageable amount of files to have in site/templates.

If you use PHP files for parts of your pages, components, etc., you can use snippets (in site/snippets), or you can put them in arbitrary subfolders in your template folder (e.g. site/templates/parts, site/templates/components) and include them.

It’s less about total numbers of templates and more about my own neurotic tendencies. I get pretty “retentive” about stupid stuff like that.

Is this still not possible? Some info on that would be cool! Thanks

Instead of putting templates into subfolders, you can register them in a plugin, which would give you the option to manage them in separate folders (within the plugin).

Aaah thank you so much! for some reason I didn’t see that when I looked at Templates…
Thanks!

How does this work? I have created a plugin and using this code. But unfortunately it doesn’t load the template in the subfolder.

Please describe the steps you did in detail. Thanks.

I created a plugin with an index.php and the content:

<?php
Kirby::plugin('user/templates-folder', [
    'templates' => [
        'user' => __DIR__ . '/templates/user/user.php'
    ]
]);

And where did you put user.php

I put user.php in the /user subfolder from /templates.

But you need to put it into your plugin folder, not the /site/templates folder.