Hi everyone,
I am creating a custom field and I need to get the current page preview url in my controller.
I tried accessing the page()
object but it always gives me the home page.
Let’s take a simple example:
<?php
class CustomField extends InfoField {
// this will display the preview url in the form
public function __construct() {
$this->text = 'Your page will be served at '.$currentPage->url(); // $currentPage is what I need
}
}
Any idea?
EDIT:
I’ve made it work with this fixture:
<?php
class CustomField extends InfoField {
// this will display the preview url in the form
public function __construct() {
$page = page(str_replace('views/pages/show/', '', panel()->path)); // awful, but works
$this->text = 'Your page will be served at '.$page->url();
}
}
I’m still looking for a proper way to do this.