flokosiol / viewmode
Kirby plugin to render a page in different view modes
Fund package maintenance!
www.paypal.me/flokosiol
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:kirby-plugin
Requires
- getkirby/cms: ^4.0 || ^5.0
- getkirby/composer-installer: ^1.1
README
With this plugin for Kirby CMS you can display pages in different view modes. More details to come …
⚙️ Requirements
- Kirby CMS, Version 4+
💰 Commercial Usage
This plugin is free but if you use it in a commercial project please consider to make a donation.
🛠️ Installation
Composer
It is recommended to install the plugin via Composer:
composer require flokosiol/viewmode
Download
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/
Git Submodule
If you prefer git submodules, this ist your command:
git submodule add https://github.com/flokosiol/kirby-viewmode.git site/plugins/viewmode
🧑💻 Usage
1. View Mode Templates
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.
2. Using the view mode
To render a page in the declared view mode add this to your template code …
<?= $page->viewMode('myviewmode') ?>
3. Route Blocking (optional)
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 :)
⚠️ Handle with care!
return [ 'flokosiol.viewmode.blockedRoutes' => [ '(:all).teaser', ], ];
📋 License
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.