In my blueprint I’d like to provide a select field that renders the actually used template names of the subpages into its options. So, if a page only has subpages of type 1+2, only those appear in the select field; if a page has three types of subpages, all three appear:
subpage_type1
subpage_type2
subpage_type3
pluck would allow me to create a select field that lists all values in use in some field within the content files (e.g. for tags). But how do I get something similar that returns all template names in a collection of pages?
you could add a custom method like “allChildrenTemplates” to the model of the parent page returning an array. then call that function in the blueprint query.
Great hint, thank you @bnomei - that was exactly the pointer I needed to learn solving this!
For the possible benefit of others, here’s what I did and works (I ended up using a page method rather than a page model, as this is used in multiple blueprints):
I should have found (or better read) this post 2 hours earlier - incredible helpful!
The only thing I had to change was: $templatenames[] = $childpage->intendedTemplate()->name(); because I was getting the parent template. Any idea why?
I don’t really have an idea why you’d get the parent template, but intendedTemplate() is definitely the more robust way in any case as it also works in case no template exists for a page’s blueprint. Thank you for pointing that out