skripteria / wn-snowflake-plugin

MIT License
6 stars 4 forks source link

Snowflake for Winter CMS

Version history:

composer require skripteria/wn-snowflake-plugin

php artisan winter:up

Why a new "CMS" within a CMS at all?

In real life there are at least 4 different user types that all need to be taken care of the same time:

The first 3 customer types are regularly taken into consideration when talking about how a CMS should look like, the last user type is often been forgotten.

However, when you develop a site for a paying customer the last customer type is the one that you will end up with.

The consequence is that you need to make content management bullet proof and hide everything but the very specific pieces of content that need to be managed.

Snowflake takes care of this by automizing the power the Winter CMS backend framework.

Using Snowflake

Once installed, you first need to add the Snowflake component to any CMS Layout you want it to be used in. This will allow to use the Snowflake Twig Filter on the Layout itself and any Page that is using this Layout.

On these CMS pages you can now add some content variables using the 'sf' Twig Filter, e.g.:

<h1>{{ my_headline | sf('text', 'My awsome headline', 'Main headline of this page.') }}</h1>

The first part ('my_headline') is the Snowflake Key that will be used to render the content. The Snowflake Key is just like a normal Twig variable as a reference to the content.

Every Snowflake Key must be unique within a given Page but may conflict with the keys from other Pages. When adding Snowflake Keys to a Layout name collisions with Pages can happen, therefore it is recommended generally prefix Snowflake Keys in layouts (e.g. 'layout_my_headline').

The 'sf' filter then takes up to 3 arguments:

Please note that the characters ',' and '|' (comma and pipe) must not be used within arguments.

Currently Snowflake supports 7 standard types and 5 special ones.

The standard types are:

The 3 special cases are:

Synchronizing with the Snowflake Backend

If you are using the Winter CMS backend to edit your code, all you need to do is to save your Page or Layout, Snowflake will automatically create or update the respective records in the database.

Once a Snowflake Key is removed (or renamed) it will be handled as unused database record by the following logic:

Alternatively there is a console command to sync all CMS Pages and Layouts:

php artisan snowflake:sync

You can use it to clean up all unused Snowflake Keys (caution - this also deletes the attached content):

php artisan snowflake:sync --cleanup