Download the PHP package ugie-cake/cakephp-content-blocks without Composer
On this page you can find all versions of the php package ugie-cake/cakephp-content-blocks. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ugie-cake/cakephp-content-blocks
More information about ugie-cake/cakephp-content-blocks
Files in ugie-cake/cakephp-content-blocks
Package cakephp-content-blocks
Short Description ContentBlocks plugin for CakePHP
License MIT
Informations about the package cakephp-content-blocks
ContentBlocks plugin for CakePHP
- About
- Usage
- Install plugin via composer
- Load the plugin
- Load the View Helper
- Create the
content_blocks
table in your database - Define content blocks
- Insert defined content blocks into database
- Link to the admin interface
- Use content blocks in views
- Overriding admin page templates
- Skipping Authorization check
- Reference
- HTML Block
- Adding a HTML block
- Rendering a HTML block
- Text Block
- Adding an text block
- Image Block
- Adding an image block
About
Make previously-static parts of your website dynamic. Allow administrators and end users to edit blocks of content on the website without having to edit template files.
The left and right screenshots below show the same view + layout, but the administrator was able to modify the logo, title, main content, and footer text. All this with only a few lines of code in the CakePHP application:
And here is the administration interface for viewing and editing content blocks:
Usage
Install plugin via composer
Install this plugin into your CakePHP application using composer.
Load the plugin
You can either use the cake
CLI:
or manualy add the following line to the bootstrap()
function of your src/Application.php
file:
Load the View Helper
Add the following line to the initialize()
function of your src/View/AppView.php
file:
Create the content_blocks
table in your database
NOTE: This must be done for each environment you deploy your website to (localhost, dev, prod, etc). It also requires you to have setup your
app.php
orapp_local.php
file with an appropriateDatasources
block to connect to the database.
Define content blocks
Prior to showing content in your templates, you must first define what blocks are available.
This is done by inserting records into the content_blocks
table, which is most easily done via Seeds.
Here is an example seed to create one content block of each type (html
, text
, and image
):
Insert defined content blocks into database
Once you have defined your content blocks in a seed (see above), then you can run the "Seed" to create the records in the database:
Link to the admin interface
In order for your administrators to be able to access the content blocks admin page,
your template needs to link to the ContentBlocks
controller index
action:
Use content blocks in views
Instead of hard coding content into views, output relevant content blocks. This means that administrators never need to make code changes (or employ someone to make code changes) if they require changes to most parts of the template.
This is done using the relevant ContentBlocksHelper
functions:
Overriding admin page templates
For various reasons, you may want to customise the appearance of the admin pages. If this is the case, you can override the provided templates by creating a folder in your CakePHP application's templates
folder called plugin
(if you have not already), and creating the path ContentBlocks/ContentBlocks
(that is, a folder inside a folder) inside the plugin
folder. The directory structure should look like so:
Skipping Authorization check
You may see error messages such as The request to `/content-blocks/content-blocks` did not apply any authorization checks
if you have implemented Authorization plugin in your project, but did not add policies required. You may need to skip the authorization check in the content-blocks
plugin by adding the following configuration key:
Reference
HTML Block
Adding a HTML block
Add a new record to the content_blocks
table with a type
of html
.
An example seed can be found in the HtmlBlockSeed.php
file:
Rendering a HTML block
In a layout or view template, add the following:
Text Block
Adding an text block
Add a new record to the content_blocks
table with a type
of text
.
An example seed can be found in the TextBlockSeed.php
file:
Image Block
Adding an image block
Add a new record to the content_blocks
table with a type
of image
.
An example seed can be found in the ImageBlockSeed.php
file:
All versions of cakephp-content-blocks with dependencies
cakephp/cakephp Version ^5.0
ext-json Version *
ezyang/htmlpurifier Version ^4.16