sage: Custom templates not loading since latest update
Submit a feature request or bug report
- I’ve read the guidelines for Contributing to Roots Projects
- This is a feature request
- This is a bug report
- This request isn’t a duplicate of an existing issue
- I’ve read the docs and NPM Debugging Guidelines post and followed them (if applicable)
- This is not a personal support request that should be posted on the Roots Discourse forums
Bug report
It looks like after the latest update of sage, the custom templates aren’t working anymore. I tested it on two different installations and for both the custom templates don’t appear under page attributes. I guess it has something to do with the move of templates/ to resources/views/ and src/ to app/ but unfortunately I wasn’t able to figure out where the problem is.
Specifically I’m talking about this template/templates resources/views/template-custom.blade.php
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 25 (23 by maintainers)
Commits related to this issue
- Move required theme files to sage/resources * Resolves issue with WP only looking one-level deep for templates #1870 * get_template_dir() and related functions now point to sage/resources * Use colle... — committed to roots/sage by QWp6t 7 years ago
- Move required theme files to sage/resources * Resolves issue with WP only looking one-level deep for templates #1870 * get_template_dir() and related functions now point to sage/resources * Use colle... — committed to roots/sage by QWp6t 7 years ago
- Move required theme files to sage/resources * Resolves issue with WP only looking one-level deep for templates #1870 * get_template_dir() and related functions now point to sage/resources * Use colle... — committed to roots/sage by QWp6t 7 years ago
- Move required theme files to sage/resources * Resolves issue with WP only looking one-level deep for templates #1870 * get_template_dir() and related functions now point to sage/resources * Use colle... — committed to roots/sage by QWp6t 7 years ago
- Move required theme files to sage/resources * Resolves issue with WP only looking one-level deep for templates #1870 * get_template_dir() and related functions now point to sage/resources * Use colle... — committed to roots/sage by QWp6t 7 years ago
it looks like wordpress hardcodes looking for page templates beyond 1 level deep 😱, see http://wordpress.stackexchange.com/a/250024 / https://github.com/WordPress/WordPress/blob/503d42fe6bcd2f45b3af78657686f8a27ccb0136/wp-includes/class-wp-theme.php#L1034-L1045
from what i can tell so far, we’d have to duplicate the
get_post_templatesfunctionality and tell it to search beyond 1 folder deep…then use the
theme_page_templatesfilter to populate the list of template names & filenamesThe following line
$post_templates[$type][$file] = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $header[1]));should be changed to$post_templates[$type][$full_path] = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $header[1]));to maintain coherence with wordpress’ internal way of setting post template meta - and because changing it to a numerical id breaks ACF way of setting the rule for Page Templates.oh jeeze
Alright so after playing with it for a bit I got to this working solution:
Any feedback is most welcome. If accepted I’m happy to open a PR with it 😃
Thanks @ciromattia for pointing that out, code updated 😄