I am facing a challenge and hope you can help me. So far I have used the method
page('page_id')
in my code to query pages. But now I would like to switch to
page('page_blueprint_name')
The reason for this is that I have defined a rule in my plugin to check whether certain blueprints are already in use. Unfortunately, I don’t know in advance what the name of the page title I will use later will be. Therefore, I would like to use the name of the blueprint to identify the page.
So my question to you is: Is it possible to search or find pages based on the blueprint used? And if so, what is the best way to do this?
I would be very grateful for your help!
PS:
Otherwise, I would declare a hidden value of the blueprint name that I would use with
Could you please give me an approach on how to solve it? I tried a lot of things and I don’t think I could solve it with intendedTemplate. But I probably went about it the wrong way.
If I would reset everything and work with yml and php files. I can create the reports in the PageModel (without having to write a plugin).
Can I then also create the dynamic sections?
My previous attempts only gave me an empty array in the panel, but in the frontend template alls as expected.
I have now also tried to get the PageModels into the plugin and also get no report output about the respective page.
In the end, my goal is to create an extension that provides everything necessary with the in-house resources of Kirby a ready-made CMS. This includes the blueprints, models, templates and controllers.
So that when I use my extension I have a CMS with the pre-defined possibilities to fill a website with content. The entire front end is also provided completely.
The dynamic sections only work with PHP blueprints, at least if the number of sections is not predefined. In a YAML blueprint, you could only create a fixed number of sections.
You need the PHP approach to be able to loop through a dynamic list of properties you want to filter by.
And how is it possible for me, if I create a page from my plugin with a blueprint which may/can only be used once, but I do not know how the page is named, to output the reports via the PageModel from the plugin with data.
If I have understood you correctly then I can only use
page('pagename')->children()->listed()->count()
to output the count via the PageModel in the reports() if I know the page name, but it is unknown to me.
Or am I just too stuck to think outside the box?
If you can help me with this, I would be very grateful.
We don’t have access to the current page object in the PHP blueprint files, and therefore have to hard-code the pages we want to fetch via PHP. So the possibilities we have with this type of setup are not endless but useful in certain situations.
So you cannot fetch pages dynamically, but only by ID/UUID
Or in other words, if you don’t know the id/uuid, you do not have access to the page.
In a PHP blueprint, you don’t have access to the current page object, unless you know the ID. So storing a value in the page itself will not help with this.
But this only affects blueprints. In your frontend templates, that’s another story, and you have of course access to the current page and can find pages by all sorts of criteria, including the blueprint used (via $page->findBy('intendedTemplate')).
Yes, I understood that, I just have to see if I can trick or if I prepare everything without a plugin and then always copy the files into a new Kirby project.
I just wanted to leave a message that I have found a solution.
Since I already had a function that prevented me from creating several pages with the same blueprint, I simply created an additional array and then passed this on to my page blueprint. Due to the fact that only one entry can/may exist, I was then able to find the page based on the blueprint used.