Custom page templates in subfolder

Hello all,

I am struggling with getting sage to recognise subfolders within a directory (e.g. resources/third-party) as valid places for custom page templates.

I have tried adding the subfolder to filter_templates on app/helpers.php, altering the view paths on config/views.php and adding a sage/filter_templates/paths filter, none of which made any difference as Wordpress would not add the custom templates to the Page attributes > Template selector.

I had very limited success by adding a theme_[$post_type]_templates filter, which allowed me to see and select the templates when editing a page, but did not actually use the selected template when the page was accessed.

Is this something sage allows one to do at all or should I give up on getting this to work?

If I understand the problem correctly, I believe this tool I wrote should help: https://github.com/alwaysblank/plumbing-templates

Hmmmm…it could help, thanks! Does it support nesting?

To give a bit more insight in what I’m trying to achieve: this is a magazine which often features stories with custom templates and design (e.g. infographics to scroll-triggered animations). So far this has been done in-house, but moving forward the idea is to have guest developers for some of those. My initial approach would be to have this directory (such as resources/third-party) which would itself contain several other folders (e.g. resources/third-party/story-1, resources/third-party/story-2) which would finally have all the template-related code (assets, styles, js).

I don’t think it supports nesting in the way you’re describing it, although it probably wouldn’t be difficult to modify it to recurse into subdirectories.

Your use case is probably beyond the scope of that tool, though: All it’s meant to do is allow people to put template files in other places. To do what you’re describing is somewhat more complicated.

Just to give this thread some closure: @alwaysblank’s package would definitely help in organising custom page templates and could indeed support nesting – I started sketching something, but could never have workable code due to other things requiring my attention.

The goal stated on my previous post seems very impractical to reach within sage 9, so I decided for an alternative approach.

@alwaysblank: Sorry, I didn’t mean to imply that your tool would solve all the problems related to what I’m trying to do, I just wanted to give some context. Thanks for your help!

1 Like