Skip to content

Back to Notes on Kirby CMS

Panel shortcuts for the front-end

To add a log out link to the front-end:

<a href='/panel/logout'>Log out</a>

To check that the current user can edit a certain page, use:

<?php if ($page->permissions()->can('update')): ?>
...
<?php endif ?>

To add Panel shortcuts:

<footer>
<?php if($user->role()->permissions()->for('access', 'panel')): ?>
    Admin: 
    <a href='<?= $page->panel()->url() ?>?language=<?= $kirby->language() ?>'>
        <?= t('Edit page') ?>
    </a>
    <a href='<?= $site->panel()->url() ?>?language=<?= $kirby->language() ?>'>
        <?= t('Admin panel') ?>
    </a>
<?php endif; ?>
</footer>

Caveat: interaction with the cache

TODO: investigate how the technique interacts with Kirby’s built-in page cache.

The plugin pechente/kirby-admin-bar raises an interesting point about the limitations of this approach:

Please note that this plugin might disable Kirby staticache since it renders different content for logged-in users and guests.

The tan3/kirby-edit-button plugin works around the caching issue by checking for user authentication with JavaScript.