With this plugin for Kirby CMS you can display pages in different view modes. More details to come …
- Kirby CMS, Version 4+
This plugin is free but if you use it in a commercial project please consider to make a donation.
It is recommended to install the plugin via Composer:
composer require flokosiol/viewmode
Alternatively you can download and extract this repository, rename the folder to viewmode
and drop it into the plugins folder of your Kirby installation. You should end up with a folder structure like this:
site/plugins/viewmode/
If you prefer git submodules, this ist your command:
git submodule add https://github.com/flokosiol/kirby-viewmode.git site/plugins/viewmode
This plugin is based on content representations. If you want to add a view mode to one of your page types you need to add a template to your templates
folder like you do for content representations:
site/templates/mypagetype.myviewmode.php
The dafault template for the page type should already exists next to it.
site/templates/mypagetype.php
Inside your view mode template you can add the template code you want to use for the page when it's rendered in this particular view mode – just like you do in a normale page template or a snippet.
Like every other content representation you can make use of controllers to simplify your template code.
To render a page in the declared view mode add this to your template code …
<?= $page->viewMode('myviewmode') ?>
The view modes (a.k.a. content representations) are by design accessible via their URL. This is intended! Otherwise content representions wouldn't make any sense. But since we use it for a different purpose, we might want to block these pages. If the regular page e.g. is https://mydomain.com/articles/my-latest-article
a view mode teaser
would be accessible via https://mydomain.com/articles/my-latest-article.teaser
.
To block all URLs for the teaser
view mode, add this to your config.php
. This blocks all URLs of your whole website which ends on .teaser
. Make sure to double check these settings. Otherwise you might block some pages by mistake. If you notice that strange error pages appear on your website, this would be the first place to look :)
return [
'flokosiol.viewmode.blockedRoutes' => [
'(:all).teaser',
],
];
It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.