I see now that I wrote it a little weird. I’ll try to explain better.
If the template that I use, only have a blueprint and not a template file, then the controller can’t match it because it does not exist (it only exists as blueprint). Instead it looks for a controller for the default template.
I think that is a little bit weird. I think it should match the indended template instead because that is what is setup in the blueprint as well as content. Then if the template file exists or not is not so important, I think.
What I try to say is, it should look at the blueprint and the content instead of the physical template file. Then it would still know what controller to use, not dependent of the physical template file.
Or is there any cases that we want it to fallback to look for the default controller (if it exists)?
As far as I can tell, it does not fall back to a default controller, in fact, Kirby uses the controller of the page that displays the page content, like the home controller if you build a single page website with only the home.php template and some snippets. Using patterns instead of snippets does not make any difference in this context.
I also do not get why you would want a controller based on intendedTemplate?
The controller is there to abstract stuff away from the template. In very simplified terms: Taking a lot of the PHP (logic) out of the template and just leave the display parts (HTML). That is a controller for an actual template.
What would you put into a controller for intendedTemplate? That controller would prepare things for a non-existent output/template. That leaves me confused.
And one more thing: If you were to call the intended template for each subpage within your templated page, you would end up with several different controllers for a single template, which does not really make sense, and you would have to be very careful with your logic (variables), so as not to end up with conflicting ones.
@distantnative I will explain how my code work, just so you know it from my perspective.
I use the Patterns plugin so I don’t use templates and snippets very much (almost not at all). Everything goes through the default-template and then into a pattern.
Then I have some if statements to find out what indended template is used. That way it builds a like a page template depending on the intended template and some other parameters. It works really great.
I’m using the workaround for now and it works fine, so I’m probably just going to leave it like that.
Instead of using if statements in the default template, you could still use different templates that reference the patterns. I think this is more robust and easier to understand. But as long as it works for you, your solution is fine too.
That was my thinking as well. Especially if the site becomes bigger, it will help to keep an overview of what elements are doing what.
Or if you want to be able to “change templates” via using patterns depending on user selection in the panel, you could still use templates or snippets to organize your patterns and call the snippets/templates in your main template, but then in those snippets, reference the patterns that belong to a “virtual template”.