So you can jump with just one click from any content for editing to the correct side of the panel.
Is that awesome?
HowTo
Remark:
The following is like a cookbook! You may want to change some parts of the following, to fit your needs. Feel free!
Hint: For the first try, donβt change anything and follow this description βstep by stepβ!
For this HowTo I assume that we use a newly installed and unchanged Kirby version 2.1.0. Otherwise, you need to adjust the description correspondingly.
Step 1:
Add a new file with the name βpagetitle.phpβ in the directory β/site/snippetsβ
This new file should look like:
<?php if (!isset($theTag)) $theTag = 'h1'; // no tag for the page title via the snippet variable "theTag" assigned ?>
<?php if (!isset($thePage)) $thePage = $page; // no "$page" via the snippet variable "thePage" assigned ?>
<?php if (!isset($thePageTitle)) $thePageTitle = $thePage->title(); // no "$page->title()" via the snippet variable "thePageTitle" assigned ?>
<<?php echo $theTag; ?>><?php if (isset($thePageLink)) echo '<a href="' . $thePageLink . '">'; // the url of the link in the title is in "thePageLink" or the variable "thePageLink" is empty for no link ?><?php echo html($thePageTitle); ?><?php if (isset($thePageLink)) echo '</a>'; ?><?php if($user = $site->user() and $user->hasPanelAccess()): // user is logged in and has panel access ?>
<a href="<?php echo $site->url() ?>/panel/#/pages/show/<?php echo $thePage->uri() ?>/p:1" target="<?php echo c::get('HeinerEF.EditTarget', '_blank'); ?>" title="Edit page data (in new window / tab)" class="admineditlink"><sup class="fa fa-cog admincolor"></sup></a><?php endif; ?>
</<?php echo $theTag; ?>>
Step 2:
Open all *.php files in the folder β/site/templatesβ and search for β<h1><?php echo $page->title()->html() ?></h1>β.
Replace all results with β<?php snippet('pagetitle') ?>β.
Hint to @jenstornellDonβt require title in the blueprint:
You can replace the written title by replacing the results e.g. with β<?php snippet('pagetitle', array('thePageTitle' => $page->page_title())); ?>β.
Step 3:
Open the file βprojects.phpβ in the folder β/site/snippetsβ and search for β<h3><a href="<?php echo $project->url() ?>"><?php echo $project->title()->html() ?></a></h3>β.
Replace it with β<?php snippet('pagetitle', array('theTag' => 'h3', 'thePage' => $project, 'thePageLink' => $project->url())); ?>β.
Step 4:
Within your CSS file βassets/css/main.cssβ add these lines at the end of the file:
/* =================================================
* HowTo: Working with contextual links to the panel
* =================================================
*/
@font-face {
font-family: 'FontAwesome';
font-weight: normal;
font-style: normal;
src: url(../../panel/assets/fonts/fontawesome-webfont.woff) format('woff');
}
.fa {
display: inline-block;
font-family: FontAwesome;
font-feature-settings: normal;
font-kerning: auto;
font-language-override: normal;
font-size-adjust: none;
font-stretch: normal;
font-style: normal;
font-synthesis: weight style;
font-variant: normal;
font-weight: normal;
line-height: 1;
text-rendering: auto;
}
.fa-cog:before {
content: "\f013";
}
/* The following color is deliberately garish chosen to show the gear wheels significantly. Please adjust (later)! */
.admincolor {
color: #F0F;
}
Step 5:
Log in at the panel and keep logged in.
Go to your website in another browser window (being logged in).
Click at a gear wheel! Then enjoy!
Next Steps:
Go to another page of your website (being logged in) and there click at a gear wheel.
You may want to look at your website as a guest (not logged in) and logged in as a user without panel access, if you have this type of user!
Modify the file βpagetitle.phpβ in the directory β/site/snippetsβ to fit your needs.
Modify and extend the CSS file and extend the file βconfig.phpβ in the directory β/site/configβ (in this post I show only the main elements, you need to test this idea).
Add a login panel/page on the site itself and a link to it for a login without opening the panel. Details can be found on Kirby docs: Solutions > Authentication.
This looks like a great addition, so customers can easily edit their content without having to look up the specific content.
What would enhance this even further is to use a small login panel on the site itself without opening the panel so one could immediately edit the content on the site this way.
With Kirby version 2.2.x the adress of the panel pages have changed.
Therefore, the file in Step 1 is as follows:
<?php if (!isset($theTag)) $theTag = 'h1'; // no tag for the page title via the snippet variable "theTag" assigned ?>
<?php if (!isset($thePage)) $thePage = $page; // no "$page" via the snippet variable "thePage" assigned ?>
<?php if (!isset($thePageTitle)) $thePageTitle = $thePage->title(); // no "$page->title()" via the snippet variable "thePageTitle" assigned ?>
<<?php echo $theTag; ?>><?php if (isset($thePageLink)) echo '<a href="' . $thePageLink . '">'; // the url of the link in the title is in "thePageLink" or the variable "thePageLink" is empty for no link ?><?php echo html($thePageTitle); ?><?php if (isset($thePageLink)) echo '</a>'; ?><?php if($user = $site->user() and $user->hasPanelAccess()): // user is logged in and has panel access ?>
<a href="<?php echo $site->url() ?>/panel/pages/<?php echo $thePage->uri() ?>/edit" target="<?php echo c::get('HeinerEF.EditTarget', '_blank'); ?>" title="Edit page data (in new window / tab)" class="admineditlink"><sup class="fa fa-cog admincolor"></sup></a><?php endif; ?>
</<?php echo $theTag; ?>>
With Kirby version 3.x the adress of the panel pages and more has changed.
Therefore, the file in Step 1 is as follows:
<?php if (!isset($theTag)) $theTag = 'h1'; // no tag for the page title via the snippet variable "theTag" assigned ?>
<?php if (!isset($thePage)) $thePage = $page; // no "$page" via the snippet variable "thePage" assigned ?>
<?php if (!isset($thePageTitle)) $thePageTitle = $thePage->title(); // no "$page->title()" via the snippet variable "thePageTitle" assigned ?>
<<?php echo $theTag; ?>><?php if (isset($thePageLink)) echo '<a href="' . $thePageLink . '">'; // the url of the link in the title is in "thePageLink" or the variable "thePageLink" is empty for no link ?><?php echo html($thePageTitle); ?><?php if (isset($thePageLink)) echo '</a>'; ?><?php if($user = kirby()->user() and $user->role()->permissions()->for('access', 'panel')): // user is logged in and has panel access ?>
<a href="<?php echo $thePage->panelUrl(); ?>" target="<?php echo c::get('HeinerEF.EditTarget', '_blank'); ?>" title="Edit page data (in new window / tab)" class="admineditlink"><sup class="fa fa-cog admincolor"></sup></a><?php endif; ?>
</<?php echo $theTag; ?>>
I updated and extended the snippet for Kirby 3, following @texnixeβs hints.
Therefore the file in Step 1 is as follows:
<?php
/* Kirby 3.x snippet: pagetitle.php
* last update 10.08.2019 by @HeinerEF (check, if user can read the page in the panel)
* update 09.08.2019 by @HeinerEF (using the hints from @texnixe at https://forum.getkirby.com/t/howto-working-with-contextual-links-to-the-panel/1566/9)
*/
$theTag = $theTag ?? 'h1'; // the tag for the page title via the snippet variable "theTag" assigned or 'h1'
// $theTagAddon // the e.g. "class-text" in the pagetitle tag via the snippet variable "theTagAddon" assigned (including 'class="..."')
$thePage = $thePage ?? $page; // the "$page" via the snippet variable "thePage" assigned
$thePageTitle = $thePageTitle ?? $thePage->title(); // the "$page->title()" via the snippet variable "thePageTitle" assigned
$thePageTitle = str_replace('</<wbr>', '</', str_replace('/', '/<wbr>', html($thePageTitle))); // add '<wbr>' after each '/' in the visible text of the title
// $thePageTitleAddon // the "Addon text" after the page title via the snippet variable "thePageTitleAddon" assigned
// $thePageLink // the url of the link in the title is in "thePageLink" or the variable "thePageLink" is empty for no link
?>
<<?= $theTag; ?><?php if (isset($theTagAddon)) echo ' ' .$theTagAddon; ?>><?php if (isset($thePageLink)) echo '<a href="' . $thePageLink . '">'; ?><?= $thePageTitle; ?><?php if (isset($thePageLink)) echo '</a>'; ?><?php if (isset($thePageTitleAddon)) echo $thePageTitleAddon; ?><?php if($user = kirby()->user() and $user->role()->permissions()->for('access', 'panel') and $thePage->permissions()->can('read')): // user is logged in and has panel access and can read the page in the panel ?><a href="<?= $thePage->panelUrl(); ?>" target="<?= option('HeinerEF.EditTarget', '_blank'); ?>" title="Edit page data (in new window / tab)" class="admineditlink"><sup class="fa fa-cog admincolor"></sup></a><?php endif; ?></<?= $theTag; ?>>