Jump to content

[Feature Request] First-class support for organizing template files in subdirectories


Recommended Posts

Posted

I’d like to bring attention to a long-standing organizational issue that affects projects with many template files. As projects grow, the 

/site/templates/

 directory becomes cluttered with dozens (or even hundreds) of PHP files, making it difficult to maintain and navigate.

The Problem

Currently, ProcessWire doesn’t natively support organizing template files into subdirectories. For example, if you want to organize templates like this:

/site/templates/
  ├── warehouse/
  │   ├── dashboard.php
  │   ├── packing.php
  │   └── packages.php
  ├── customer/
  │   ├── dashboard.php
  │   └── packages.php
  └── sso/
      ├── login.php
      └── callback.php

You currently face several challenges:

  1. Alternate Template Filename field is unreliable - The admin interface often strips or resets the path when saving, especially if the file doesn’t exist at that exact moment
  2. No automatic discovery - You must manually configure each template’s file path
  3. Hooks don’t work as expected - Attempts to hook 
    TemplateFile::getFilename
     or 
    Template::getFilename
     don’t fire reliably

Current Workarounds

The existing workarounds are less than ideal:

1. Bridge files as suggested by @LostKobrakai

// site/templates/warehouse-dashboard.php
<?php namespace ProcessWire;
include(__DIR__ . '/warehouse/dashboard.php');

This creates file duplication and maintenance overhead.

2. Manual Alternate Template Filename for each template:
- Requires clicking through every template
- Path validation often fails
- No bulk operations

Previous Discussions

This has been requested multiple times over the years:

Proposed Solution

I’ve opened a GitHub feature request with detailed suggestions:
https://github.com/processwire/processwire-requests/issues/575

The core ideas:
1. Path persistence - The Alternate Template Filename field should reliably save paths like folder/filename.php
2. Automatic discovery - If a template named warehouse-dashboard isn’t found, check for /warehouse/dashboard.php
3. Template grouping in admin - Visual organization in Setup → Templates based on folder structure

Why This Matters

  • Large projects - Sites with 50+ templates become unmanageable
  • Team development - Clear organization helps multiple developers
  • Module development - Modules could bundle template files cleanly
  • Modern standards - Most frameworks support organized file structures

Use Cases

This would benefit:

  • Multi-role applications (admin, customer, warehouse staff interfaces)
  • Projects with many page types
  • Module developers who want to bundle templates
  • Anyone with SSO/OAuth files, API endpoints, or admin tools

What Can You Do?

If you’ve faced this issue or would like this feature:
1. 👍 React to the GitHub issue
2. Share your use cases below
3. Suggest implementation approaches

@ryan - Would love to hear your thoughts on this! Is this something that could be considered for a future release?


Thanks for reading, and I hope this resonates with others who’ve felt this pain!

  • Like 7
Posted
45 minutes ago, maximus said:

2. Share your use cases below

Similarly, custom page classes suffer from the same limitation. Their files can only be dumped in one directory, we have no options to organize them.

I have also tried various workarounds ever since I started using ProcessWire, but none of them came even close to some sort of proper native support.

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...