CMS
Content Management System built on Twig and Laravel, (*1)
Install using composer require siipis/cms
, (*2)
Known issues
Template caching causes problems with page configuration. You can either regularly clear the cache by running the console command twig:clean
or by disabling the cache altogether., (*3)
Set 'cache' => false,
in the twigbridge.php
config file to disable caching., (*4)
Usage
Service provider & Facade
Add the following lines in the app.php
config file:, (*5)
Providers:, (*6)
Siipis\CMS\ServiceProvider::class,
Aliases:, (*7)
'Twig' => TwigBridge\Facade\Twig::class,
'YAML' => Symfony\Component\Yaml\Yaml::class,
'CMS' => Siipis\CMS\Facade\CMS::class,
'CMS_Helper'=> Siipis\CMS\Facade\Scaffolding::class,
'CMS_Parser'=> Siipis\CMS\Facade\Parser::class,
Routing
Add at the end of the routes.php
file, (*8)
/*
* Catch-all route for views
*/
Route::get('{route}', function ($route) {
return CMS::view($route);
})->where('route', '.*');
Add a twig file under resources/views/pages
to serve the view without a controller in between., (*9)
Within controllers
CMS views can be served through the CMS facade using CMS::view('page')
. Note that paths are relative to the pages directory., (*10)
Folder configuration
Place the following directories directly under the template root (default resources/views
), (*11)
- layout
- menus
- pages
- partials
Extended Twig syntax
{% page %}
Used in layout files for indicating where the page is placed in the layout., (*12)
Placeholder tag for the page title., (*13)
Include helpers
The following helper tags are included to clean up the syntax. All paths are relative to the include type., (*14)
- {% menu 'filename' %}
- {% partial 'filename' %}
Layout pages
The pagecontains an optional config section in the beginning of the file. The divider is ===
., (*15)
Typical layout file:, (*16)
title: Welcome
layout: default
with:
- world: "Twig"
data:
- users:all
===
Hello {{ world }}
<br />
{% for user in users %}
<p>{{ user.name }}</p>
{% endfor %}
-
title
: Page title, appended using
-
layout
: Name of a file in the layout directory, with or without the .twig extension
-
with
: Key value attributes to be sent to the page
-
data
: Data provider accessor
Data Providers
Data providers extend the CMS\DataProvider
class and can be used to serve data without a controller., (*17)
Use php artisan make:data ProviderName
to create a new data provider. By default data providers are located in the app/CMS/Data
directory., (*18)
Data providers must implement three methods:
* getAccessor
: name of the accessor called by the config, e.g. 'users'
* dataAll()
: returns all entries, called with <accessor>:all
* dataOne($id)
: returns a single entry, called with <accessor>:one[1]
, (*19)
Additional methods can be created by additional methods., (*20)
Accessing the data
The data is automatically sent to the view and can be accessed by the accessor name, e.g. {{ users }}
. If users:one[1]
was called, the accessor is in singular, i.e. user
., (*21)
Pseudo numbers
Accessor methods accept the following pseudo numbers (example: users:one[#auth]):, (*22)
-
#auth
: returns the id of the authenticated user, or null if no login exists
-
#url
: returns the last url query, e.g. http://example.com/foo/bar
returns bar
The pseudo numbers are defined in CMS\Parser\DataParser.php
., (*23)