-
Notifications
You must be signed in to change notification settings - Fork 44
Controllers for CPT Templates #86
Comments
If you inspect the site, check the body classes ending with That's the hierarchy that Controllers will follow and any of those classes could be used. |
Ah, I did try using some of the body classes as controller names like Here's what I have on body:
Is this something that Controller supports yet? |
I'm having the same issue with a CPT. my body tag is this:
my controller
the template
is rendered, but the ACF variables as well as the test variable $test_text aren't found, eg:
|
Ah, figured out my issue from this closed ticket: #63 Should have read the original question for this ticket more closely, as I don't think my issue relates. For anyone else having this problem though, cpt template files typically aren't found by the controller owing to the underscore_then-dash pattern. To get around this tell the controller which template to use by adding, for example:
or in my case
As per the documentation on template override https://github.com/soberwp/controller#template-override-option |
@codepuncher Controller uses https://github.com/Brain-WP/Hierarchy to determine the hierarchy (and therefore Controllers to load). You could raise an issue there regarding more granular control of post type templates. If updated there, Controller would work as expected above. I'm going to close for now as this could be considered edge case, but would recommend raising on their repo to see if we can get this working down the line. |
Opened issue @ Brain-WP/Hierarchy#14 (comment) For those who stumble upon this looking for a solution, open
and add this before it
This allows me to use my template |
I've done a lot of looking into this through the reported issues, Discourse and on Google but I can't seem to find an answer for what I'm looking for. Maybe this is a very specific case-scenario where I may not be able to achieve what I'm trying to do.
I have a Post Type
event
which allows user to choose which template they want to use:What I'm trying to achieve is to separate methods and code so that all Event Singles will load
SingleEvent
or at least the traits it needs. Then the "Featured" Event Singles that use that other template will use the same traits but also the extra featured event trait.Now, assuming that the hierarchy will support this, I have setup 2 controllers
SingleEvent
andSingleEventFeatured
and created 3 traits.SingleEvent
loads 2 of them andSingleEventFeatured
loads all 3 (3rd trait for specific "Featured Event" methods).SingleEvent
correctly loads on all Event Singles, regardless of template chosen. So I'm now stuck with how to get the specific featured code to load specifically only on mysingle-event-featured.blade.php
template. I've usedprotected $template = 'single-event-featured';
but no luck. Only works when I do this:but then of course that will load that controller on all Event singles.
Does anyone have some kind of approach that I could use for this? Maybe I am missing something, but I feel like this is something in the hierarchy that isn't taken account for.
Any help appreciated!
The text was updated successfully, but these errors were encountered: