-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Element partial templates #14284
Element partial templates #14284
Conversation
[ci skip]
# Conflicts: # CHANGELOG.md [ci skip]
Will there be any visibility in your editor as to which template is going to be rendered as a result of I'm guessing since you said it could have different templates based on the "element type and field layout provider handle" that it wouldn't even really be possible to provide that kind of information in context? I'm just concerned that I'll be looking at some code that does Also then no way to Command-click to go to the template in question in your code either. Either way it's an optional thing, so we can pick and choose where it makes sense to use it? Looks like an update to Template Comments to add HTML comments to see where these are coming from could be in order. I believe Drupal does this type of thing for you. Pursuant to that, is there some way a plugin like Template Comments could hook in to add comments delineating where the rendered blocks came from? |
I see two common use cases for it:
Depends on whether you know which entry types/volumes/etc. are being queried.
Yeah, but it would just be a lateral change vs. a dynamic
Right.
Good question. The element query itself has a rough idea from its protected |
ahhhhhhhhhhh that makes sense :) |
IMO, the difference is that with the dynamic Element partial templates is a really cool feature and I love the idea of the |
@mmikkel My first pass at this was to add a “Partial Template” setting to entry types. But it felt a little cumbersome without any benefit. You’d still be limited to a single template per entry type (which, either way, can load nested templates depending on the context), and doing it that way meant any other element types that want to support partial templates would need to add their own settings. Where we landed, now every element type gets it for free – so long as they define a |
The benefit would be that developers would be free to structure their element partial templates however they see fit, which IMO is a pretty big one. To make it less cumbersome for people who are fine with defaults, Craft could even auto-fill the "Partial Template" setting for new entry types – just like how it autofills the "Template" setting when creating new sections.
Fair point, although I'd argue that adding support for partial templates would probably be a relatively minimal effort compared to the overall amount of work that goes into creating a custom element type. Anyway, this isn't the biggest thing in the world – just wanted to give my 2 cents 🙂 |
The era of partial templating has begun!
This adds a new
partialTemplatesPath
config setting, which can be used to store partial templates for elements.Partial templates can be used to render elements on the front end, based on their element type and field layout provider handle.
For example, entries of type
article
get the partial template_partials/entry/article.twig
.With partial templates created, templates can start calling a
render()
method on element queries, element collections, and even individual elements, which will render the partial template for each element, and return the result.