Create subpage within structure field

Hi!

Is it possible to have a pages section within a structured field which lets a panel user create a subpage instead of just choosing from an existing set of pages?

My use case is:
on an overview page there are thumbnails referring to an according subpage (front end). However the panel user wants to not only list the subpages thumbnails but also sprinkle the overview with simple text-“fields”. And of course wants to have the option of ordering those subpages thumbnails and text-“fields”.

My current approach is that those text-“fields” are actually also subpages but just with a simple textarea instead of a thumbnail etc. In the panel subpages overview I pulled the textarea’s content and put it into the info, so that the panel user can at least have a “preview”.

My question is, is it somehow possible to have a pages section within a structured field which lets a panel user create a subpage instead of just choosing from an existing set of pages? Because in a structured field the user would then be able to decide whether to create a whole subpage or just a text-“field” and also be able to order those, which is actually the most important thing.

Thx!

I attached screenshots showing the structured field which lets a panel user choose between a text-“field” and ideally a subpage.



Although I’m not quite following you (an example would be helpful), the simple answer to your question is: No. You can’t put a section inside a field. And the pages field currently has no option to create a new page.

Edit: Ah, I was too fast…

Sorry, it’s a bit complicated to explain :confused:

This would kind of be the website wip.
There are thumbnails of photo projects which link to a project-subpage with more details of the according photo project. The panel user wants to be able to sprinkle some quotes (the yellow blocks) inside the thumbnails overview. And in the panel order them.

How much content do these subpages have?

The subpages have kind of infinite content, depends on how many images the panel user is uploading. Could be 5, could be 30.

I think I’d stick with the subpages approach. What’s wrong with that from your perspective?

Maybe it’s a bit weird for the panel user, because he/she would have to enter a title and a slug in the subpage-creation-modal window for an entry that actually has no title because it’s a simple textfield. That could be a bit confusing.

Hm, I’m not so sure the structure solution would actually work better.

In any case, you would have to code a custom solution, either a create option to create a page from the structure field (don’t know if the Janitor plugin could be useful here), or a custom add form that would allow users to skip filling in a title.

Maybe this plugin could help you: https://github.com/steirico/kirby-plugin-custom-add-fields

I used it for a similar approach and it worked perfectly.

2 Likes

Does this actually allow you to remove the title field from the form as well?

Edit: it does, yeah.:fire:

1 Like

Thanks, that worked! :grinning:
Now I just hide the title and slug field and change the title afterwards with a hook to something like “textblock”.

class ProjektePage extends Page
{

    public static function create(array $props): Page
    {
        $props['content']['title'] = 'Textblock';
        
        return parent::create($props);
    }
}

(The title of all textblocks is the same, the slug is being created by the plugin automatically.)