Jump to content

Sub-directories for templates


renobird
 Share

Recommended Posts

The current project I'm working on is quite large. I've found that my templates folder is getting a little difficult to keep tidy (even with a decent naming convention).

It would be nice to create sub-directories within the templates directory that also get searched when adding new templates. Maybe a leading underscore to signify additional directories that contain templates?

Templates

_template-group-1

_template-group-2

_template-group-3

Directories without an underscore (ex: includes,tools,etc..) would continue to work as they do now.

There may be pitfalls to this approach, but I wanted to throw it out there.

Additionally, if any has another method for maintaining sanity in their templates directory, I'd love to hear about it.

  • Like 1
Link to comment
Share on other sites

I think everybody thought about this.

SInce I use delegate approach, one main.php that "all" templates use, I have a include to /views/basic-page.inc so it's pretty nice. More possibilities are there using includes.

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

I'm resurrecting this conversation in hopes that there might be a way to save my sanity.

I'm working on a site that will have dozens of "mini-sites". I have managed to organize things a bit better using the delegate approach, however, as the site grows, I can still envision ending up with dozens and dozens of "main" templates that are uncategorized in /templates/. I've been using a naming convention to keep track of them, but my concern is that down the road this too will end up unmanageable.

What I'd like to see (and I have NO idea of the ramifications with either of these suggestions) would be:

1. Somehow having sub-directories that get searched within the /templates/ directory (see my thoughts in the first post).

2. Allowing sub-directories and using something like "myfilename.template.php" to designate files that are templates.

All that said, I'm mostly mentioning all this in hopes that someone might have additional suggestions for maintaining a large amount of template files.

Link to comment
Share on other sites

Why so many template files? Is there any duplication between what you are doing from one template file and another? If so, remember never to repeat yourself and keep reusable stuff in separate includes, functions or modules. Also consider whether the different template needs might instead translate to stylesheets. But I know you have a good handle on all this stuff, so going to assume you really do need a lot of template files. In that case, I would suggest doing something like you indicated and considering your templates to be something more like template groups instead. Create a structure of pages that represent your "sub templates". Make them selectable, so that when you edit a template, you'll have a select box where you can choose a sub-template (with a field named sub_template). You can translate that page selection to a filename off a subdirectory in your /site/templates/ directory. For instance, lets say you are creating a page with template "news" and you want to have sub-templates of cnn, nbc and abc. You'd have a page structure like this to represent them:

/sub-templates/

/news/

/cnn/

/nbc/

/abc/

And a template file structure like this to represent them:

/site/templates/news.php

/news/

cnn.php

nbc.php

abc.php

Your news.php file might look like this:

include("./news/{$page->sub_template->name}.php"); 

What I'm trying to get at here is that you can create a structure of pages to represent a structure of templates.

  • Like 2
Link to comment
Share on other sites

Hi Ryan,

Yes! *slaps forehead* that's perfect! Thank you!

Using the page field would let me create a handful of unique mini-site layouts could easily be reused, instead of having to make a new one for each site.

Something like:

/templates/mini-layout-a.php

/templates/mini-layout-b.php

/templates/mini-layout-c.php

/templates/mini-layout-d.php

I need to use more descriptive names of course, but all of those templates could have unique layouts.

Thanks again.

:)

  • Like 1
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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