Preview URL on Kirby Demo

Hello,

I try to understand how in the Kirby demo the preview URL for Agency Clients redirect to the homepage.

I managed to do it myself with the preview option in the blueprint.
Parent page: preview: "/{{ site.homepage }}#{{ page.slug }}".
Subpage: preview: "/{{ site.homepage }}#{{ page.parent.slug }}".

But there no mention of the preview option in the demo kit source code.

How it’s done here?
Also another question: Can we disable the preview but not when the status is set to listed?

Thanks!

The redirection happens in the agency-client template: https://github.com/getkirby/demokit/blob/master/site/templates/agency-client.php

1 Like

Thanks! I hadn’t thought about template redirection here.

I think the best way is to use both, template redirection and preview in blueprint, so the URL on the “preview” button in the panel is the good one (with the preview blueprint option), and the original URL stay inaccessible (with template redirection).

Do you have an idea about my second question about the preview depending on the status ?

I actually think the best way is a template redirection and a custom page model overwriting the url() method:

// site/models/agency-client.php

<?php
class AgencyClientPage extends Page {
  public function url($options = null): string {
    return $this->parent()->url() . '#' . $this->slug();
  }
}

The ->url() method is not only used for the preview button in the panel. You don’t have to change any code in the frontend, either. Think of menus, search results, …

Concerning your second question: I don’t think that’s possible.

1 Like

You’re right, thank again!

I have to put a leading / to make it work because it will keep the panel url when the page is listed. It was ok when in draft.

// site/models/clients.php
<?php
class ClientsPage extends Page {
  public function url($options = null): string {
    return '/#' . $this->slug();
  }
}
// site/models/client.php
<?php
class ClientPage extends Page {
  public function url($options = null): string {
    return '/#' . $this->parent()->slug();
  }
}

I will post the idea of the preview URL depending of the page status :slight_smile:.
Edit: https://github.com/getkirby/ideas/issues/551

In that case I’d suggest site()->url() . '#' . $this->slug()

Even better! Thanks