Kirby API - make page visible when creating

Hi there,

Is it possible to make a page visible during the page’s creation via the API?

Many thanks,


Here’s how I did it (I’m sure there’s a better way to do this). My use-case: I have a front-end form that users fill out, I’ve created a controller that tries to create a page when the form is submitted. The ‘create a page part’ looks like this:

// Create a new page with some of the form values (`get()`) 
$newPage = $site->page('your-page')->children()->create('your_title', 'your_template_name', array(
    // fill in the fields of the template / blueprint with values from the form
    'title' => get("title"),
    'date'  => date('d-m-Y'),
    'description' => get("description"),
    'name' => get("name")
))->sort( $site->page('your_page')->children()->visible()->count() +1);

Now that last method (sort()) is what does the trick. It gets all the current visible pages + 1 and adds that sorting number to your newly created page. This makes your page visible.

I hope this helps :slight_smile: .

1 Like

Or look at

Good luck!

The autopublish plugin is a hook that is triggered if a page is created via the panel. If you create pages via the Kirby API, @gerardkd’s solution is the way to go.

Edit: If you want to make a page visible that is sorted by date or alphabetically, this won’t work though, but you could prepend a 0 or the date to the uid (if there is no more intelligent way of achieving that)