Proof of concept - Panel admin pages

It is currently not possible to change the sidebar, main or add a new admin page to the panel.

Admin panel page workaround

It is possible to add an admin panel page like the image below by using a panel field.

  1. Create a page in the panel
  2. Add a blueprint for it
  3. Add a field with your tool (or what it might bee)
  4. Hide stuff with CSS if needed

Blueprint

<?php if(!defined('KIRBY')) exit ?>

title: Home
pages: false
files: false
fields:
  title:
    label: Title
    type:  text

  page:
    label: My cute pie chart
    type: page

Field

My field is placed in /site/fields/page/page.php.

<?php
class PageField extends BaseField {
	public function __construct() {
		$this->type = 'page';
	}

	public function content() {
		ob_start();
		?>
		<div class="structure-entry">
			<div class="structure-entry-content">
				<p>About pie charts</p><br>
				<img src="https://pixabay.com/static/uploads/photo/2012/04/16/12/26/chart-35773_640.png" style="max-width: 300px; width: auto; height: auto;">
			</div>
		</div>
		<?php
		$html = ob_get_contents();
		ob_end_clean();
		return $html;
	}
}

Hide title field and submit button

If you want, you can hide the submit button and the title field with CSS. I did not make a CSS for this proof of concept but it’s possible (I used Chrome Developer Tool to remove stuff).

Pitfalls

This is not the native way of doing things, but it’s the only solution at the moment without hacking the core.

Hidden fields are not gone

Even if you hide the title field and the submit button they are still there, just hidden. Because the title is required, that might be an issue as well, I have not tried all cases.

Page as container

You need a page to contain the field. You might need to route it on the frontend to an error page, as it is probably not used for the frontend as all.

$_POST don’t work

I could not get $_POST to work which makes it not so flexible. Use it for presentation not administration.

You can still add fields below your tool (or whatever it might be) or on another page and then pick them up.

Inspired by @flokosiol

I got this idea when I looked at a this plugin:

It’s possible to use that field space for some kind of presentation, not just form fields.

Update - Quick and dirty

You should not use the proof of concept code. It’s just to show the idea. It’s quick and dirty, not ment for use. Look at the code by @flokosiol below if you don’t already know about brick or tpl::load. That’s the Kirby way and the correct way of doing it. You should probably avoid inline CSS as well.

1 Like

I like this idea!

Personally, I would prefer to use a separate template.php file for the html part instead of using ob_get_contents()

...
  public function content() {
    $wrapper = new Brick('div');
    $wrapper->html(tpl::load(__DIR__ . DS . 'template.php'));
    return $wrapper;
  }
...

If required, you could also pass data to the template like this …

$wrapper->html(tpl::load(__DIR__ . DS . 'template.php', array('my_data' => $my_data)));

PS: Thanks for the credits :stuck_out_tongue_winking_eye:

2 Likes

Very quick and very dirty

Yes! I forgot to mention that my code was very quick and very dirty. I just wanted to show a quick proof of concept of the idea.

I know about both brick and tpl::load and yes they are much better to use. I updated my post. I have not seen them together before like this so that was interesting.

Thanks!