# Frontend panel bar

**URL:** <https://forum.getkirby.com/t/frontend-panel-bar/1950>\
**Category:** Plugins\
**Tags:** discontinued, idea\
**Created:** [September 3, 2015, 9:25am UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950 "2015-09-03T09:25:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [September 3, 2015, 9:25am UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/1 "2015-09-03T09:25:39Z")

</div>

I did not add this into suggestions because this is not a core suggestion, but might be a good idea for a plugin.

## Panel bar frontend

WordPress have a top bar with shortcuts to the admin. I think it could be nice for Kirby too, as a plugin.

This is my idea of what it could look like (look at the black thing), very basic so far…

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/1X/9cf184596b6f59bd3fa9f9e633318f58cc305856.png)

Both “Edit page” and “Log out” are shortcuts to the panel, just plain links.

**What do you think about a plugin like that?**

## Exclude / include stuff

I’m thinking of having basic stuff as default and with a config array exclude stuff that is not needed.

**Good idea? Or would you want an array of including stuff instead?**

## Change panel bar

I think it needs to be customizable. The best way I can think of is by having a snippet with a snippet name configured in the config. That way anything can be added to the panel bar.

Now there is a left and a right side on the bar.

**Should it be two snippets, one for each side or just one?**

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [September 3, 2015, 11:23am UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/2 "2015-09-03T11:23:32Z")

</div>

The main problem I see is that Kirby does not control the styling and layout of the page. It would definitely be required to manually embed the code snippet from the template by using a plugin function to keep it clean.

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [September 3, 2015, 11:42am UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/3 "2015-09-03T11:42:14Z")

</div>

Yes and I kind of like it that way. WordPress does alot of “magic” stuff which usually end up as bloat.

If we add a function in the template I still think it would be clean, and best of all, it would be there in the code to be manipulated or deleted.

## An example

```php
<head>
    <?php panelbar::css(); ?>
</head>
<body>
    <?php panelbar('panelbar-snippet-name'); ?>
</body>

```

- The `panelbar` function loads (or class) only when a user is logged in.
- `panelbar::css()` loads the CSS from the plugin, only when a user is logged in.
- `panelbar('panelbar-snippet')` loads a snippet, only when a user is logged in.

Feedback?

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [September 3, 2015, 11:56am UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/4 "2015-09-03T11:56:04Z")

</div>

Looks good. But I wouldn’t define the snippets that way, I think this should be a global setting in the config.

So maybe just:

```php
<head>
    <?php panelbar::css(); ?>
</head>
<body>
    <?php panelbar::bar(); ?>
</body>

```

---

<div class="post-metadata">

**Author:** ![franzwalter](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/franzwalter/32/11968_2.png) [@franzwalter](https://forum.getkirby.com/u/franzwalter)\
**Post date:** [September 3, 2015, 12:23pm UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/5 "2015-09-03T12:23:59Z")

</div>

I’ve cobbled together a snippet a while ago, providing me with a deeplink to the corresponding panel-page; ideal for fixing typos etc.; styling via css as a fixed button in the lower right in my case; could be easily extended with additional links/functionalities such as _logout_ and others.

```
<?php if($user = $site->user()): ?>
  <a href="/panel/#/pages/show/<?php echo $page->uri() ?>/p:1" class="panel">EDIT</a>
<?php endif ?>
```

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [September 3, 2015, 12:40pm UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/6 "2015-09-03T12:40:56Z")

</div>

@lukasbestle I could not deside if the snippet name should be in the config or in the function. When in the config the template looks cleaner, but when in the template it’s faster to change it when needed.

It will probably be better to have it in the config after all, just because it has to do with the backend.

@franzwalter I also have a snippet of this already running on my site. I prefer to have the full url in the href, just to be safe.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [September 3, 2015, 12:56pm UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/7 "2015-09-03T12:56:23Z")

</div>

What kind of other options would you like to have in such a bar?  
Already working on a plugin.

---

<div class="post-metadata">

**Author:** ![Malvese](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/malvese/32/12375_2.png) [@Malvese](https://forum.getkirby.com/u/Malvese)\
**Post date:** [September 3, 2015, 1:11pm UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/8 "2015-09-03T13:11:41Z")

</div>

Suggestions:

- Edit (the current page) ;
- Show/Hide (the current page) ;
- Admin (link to dashboard) ;
- A list of other languages for the page if any (could be useful if there is no direct link in the front end).

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [September 3, 2015, 1:14pm UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/9 "2015-09-03T13:14:14Z")

</div>

> [@Malvese](#):
>
> - Show/Hide ami(the current page) ;

Could be hard since this wouldn’t be just a link to an existing page (frontend or panel) anymore, but an action itself

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [September 3, 2015, 1:24pm UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/10 "2015-09-03T13:24:25Z")

</div>

Very first steps: [https://github.com/distantnative/panel-bar/blob/master/panel-bar.php](https://github.com/distantnative/panel-bar/blob/master/panel-bar.php)

Implemented in the header snippet:

```auto
…
<body>
<?php echo panelbar::show() ?>

  <header class="header cf" role="banner">
…

```

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [September 3, 2015, 1:35pm UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/11 "2015-09-03T13:35:42Z")

</div>

## Started on a plugin - Did not get far

I also started on a plugin but I got stuck. I did not get far. You are probably much more skilled than me so you are welcome to continue.

## Template

```php
<?php echo panelbar::css(); ?>

```

It complains about that `$site` is undefined. The same thing with `$page`.

## Plugin class

```php
class panelbar {
    public static function css() {
        if( $site->user() ) {
            $stylesheet = c::get('panelbar.stylesheet');
            return $stylesheet;
        }
    }
    protected function __construct() { }
    private function __clone() { }
    private function __wakeup() { }
}

```

## My thoughts

- To be able to control the content with inside the bar with a snippet. Controlling it with an array can be nice at first but sooner or later you might want to control it fully.
- Set own name for the snippet. This to not collide with other files in the snippets.
- Use the icons from the panel icon font when possible.
- Use the same font as the panel. Just to make it feel like we are still in the panel.
- Use singleton pattern like @lukasbestle wrote, it looks nice.
- Prefix div classes to prevent collisions, like “pb-”.

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [September 3, 2015, 1:47pm UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/12 "2015-09-03T13:47:41Z")

</div>

> [@jenstornell](#):
>
> It complains about that $site is undefined. The same thing with $page.

That’s because `$site` and `$page` are in global scope and not in the method’s scope. You need to use `site()` and `page()`. BTW: Why are you passing `$page` to the method? You are not using the variable.

And also: The constructor and other magic methods must be public.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [September 3, 2015, 1:49pm UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/13 "2015-09-03T13:49:18Z")

</div>

Implemented a way to add custom elements to the panel bar by passing an array with functions that return the elements content:

```auto
<?php
echo panelbar::show(array(
  'custom' => function() {
                return '<div>ELEMENT</div>';
              },
  'logout'
));
?>

```

or with all default elements:

```auto
<?php
echo panelbar::show(a::merge(array(
  'custom' => function() {
                return '<div>ELEMENT</div>';
              },
), panelbar::$elements));
?>

```

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [September 3, 2015, 1:53pm UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/14 "2015-09-03T13:53:31Z")

</div>

Opps, I forgot to remove `$page` before pasting this here. I just think it’s strange because `tpl::load()` work with `$site` and `$page` without needing to passing them to the method. My own don’t.

I even tried to duplicate `tpl::load()` function (copied Kirby core code) and just renamed it `jens::load()`, but the jens-version did not work. Same problem, undefined `$site` or `$page`. I guess it’s a dependence I have not taken into account.

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [September 3, 2015, 2:09pm UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/15 "2015-09-03T14:09:57Z")

</div>

It looks like the Kirby style but if this goes directly into the template, doesn’t it get a little messy? Especially the last one?

### Maybe as a config instead?

With snippets

```php
c::set('panelbar.include') = array(
    'edit',
    'custom' => 'panel-snippet',
    'logout',
    'custom2' => 'panel-snippet2'
));

```

### Or this for all elements

```php
c::set('panelbar.include') = array(
    'all',
    'custom' => 'panel-snippet'
));

```

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [September 3, 2015, 2:11pm UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/16 "2015-09-03T14:11:12Z")

</div>

Yea, mine def needs some polishing and improvements - thanks for the input 👍

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [September 3, 2015, 2:22pm UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/17 "2015-09-03T14:22:54Z")

</div>

> [@jenstornell](#):
>
> I just think it’s strange because tpl::load() work with $site and $page without needing to passing them to the method.

The `Tpl` class is part of the Toolkit, which doesn’t know anything about `$site` and/or `$page`. Could you please link to the code you are referring to?

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [September 3, 2015, 2:33pm UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/18 "2015-09-03T14:33:36Z")

</div>

## What work

### Here is the code I tried with in my template:

```php
<?php tpl::load( kirby::instance()->roots()->snippets() . DS . 'test.php', '', ''); ?>

```

### `snippets/test.php`

```php
<?php echo $page->title(); ?>

```

This works which means that it knows about `$page` in the snippet, even if I don’t send it or make it global.

## What don’t work

I do the same thing with duplicated code from `toolkit/lib/tpl.php`

### In a plugin:

```php
class jens extends Silo {

  static public $data = array();

  static public function load($file, $data = array(), $return = true) {
    if(!file_exists($file)) return false;
    ob_start();
    extract(array_merge(static::$data, (array)$data));
    require($file);
    $content = ob_get_contents();
    ob_end_clean();
    if($return) return $content;
    echo $content;
  }

}

```

### In the template:

```php
<?php jens::load( kirby::instance()->roots()->snippets() . DS . 'test.php', '', ''); ?>

```

It makes `$page` and `$site` undefined.

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [September 3, 2015, 2:41pm UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/19 "2015-09-03T14:41:25Z")

</div>

I can see you are updating it all the time now. Can you write here when you have a version good enough for testing and feedback? Like a beta version.

I like your prefixing btw.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 3, 2015, 2:47pm UTC](https://forum.getkirby.com/t/frontend-panel-bar/1950/20 "2015-09-03T14:47:31Z")

</div>

To add my two cents to the discussion 😊 : While a page edit button makes sense for single pages like a blog articles etc., it is quite useless if pages are made up of different modules. I would therefore prefer edit buttons right where the content that needs to be edited is (like it is implemented in Joomla).

[Next page](https://forum.getkirby.com/t/frontend-panel-bar/1950.md?page=2)
