PHPackages                             ugie-cake/cakephp-content-blocks - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ugie-cake/cakephp-content-blocks

ActiveCakephp-plugin[Utility &amp; Helpers](/categories/utility)

ugie-cake/cakephp-content-blocks
================================

ContentBlocks plugin for CakePHP

v1.4.1(3mo ago)37.4k↓89.2%4[5 issues](https://github.com/ugie-cake/cakephp-content-blocks/issues)MITPHPPHP &gt;=8.1

Since Sep 16Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/ugie-cake/cakephp-content-blocks)[ Packagist](https://packagist.org/packages/ugie-cake/cakephp-content-blocks)[ RSS](/packages/ugie-cake-cakephp-content-blocks/feed)WikiDiscussions main Synced today

READMEChangelog (9)Dependencies (4)Versions (12)Used By (0)

ContentBlocks plugin for CakePHP
================================

[](#contentblocks-plugin-for-cakephp)

- [About](#about)
- [Usage](#usage)
    - [Install plugin via composer](#install-plugin-via-composer)
    - [Load the plugin](#load-the-plugin)
    - [Load the View Helper](#load-the-view-helper)
    - [Create the `content_blocks` table in your database](#create-the-content_blocks-table-in-your-database)
    - [Define content blocks](#define-content-blocks)
    - [Insert defined content blocks into database](#insert-defined-content-blocks-into-database)
    - [Link to the admin interface](#link-to-the-admin-interface)
    - [Use content blocks in views](#use-content-blocks-in-views)
    - [Overriding admin page templates](#overriding-admin-page-templates)
    - [Skipping Authorization check](#skipping-authorization-check)
- [Reference](#reference)
    - [HTML Block](#html-block)
        - [Adding a HTML block](#adding-a-html-block)
        - [Rendering a HTML block](#rendering-a-html-block)
    - [Text Block](#text-block)
        - [Adding an text block](#adding-an-text-block)
    - [Image Block](#image-block)
        - [Adding an image block](#adding-an-image-block)

About
-----

[](#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:

[![](./docs/screenshot.png)](./docs/screenshot.png)

And here is the administration interface for viewing and editing content blocks:

[![](./docs/screenshot-list.png)](./docs/screenshot-list.png)

[![](./docs/screenshot-block-html.png)](./docs/screenshot-block-html.png)

Usage
-----

[](#usage)

### Install plugin via composer

[](#install-plugin-via-composer)

Install this plugin into your CakePHP application using [composer](https://getcomposer.org).

```
composer require ugie-cake/cakephp-content-blocks

```

### Load the plugin

[](#load-the-plugin)

You can either use the `cake` CLI:

```
bin/cake plugin load ContentBlocks
```

*or* manually add the following:

```
// In src/Application.php for CakePHP addPlugin('ContentBlocks');
}

// In config/plugins.php for CakePHP >= 5.x
return [
    // ...
    // Additional plugins here
    'ContentBlocks' => [],
];
```

```
$this->addPlugin('ContentBlocks');
```

### Load the View Helper

[](#load-the-view-helper)

Add the following line to the `initialize()` function of your `src/View/AppView.php` file:

```
$this->loadHelper('ContentBlocks.ContentBlock');
```

### Create the `content_blocks` table in your database

[](#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` or `app_local.php` file with an appropriate `Datasources` block to connect to the database.

```
bin/cake migrations migrate --plugin=ContentBlocks

```

### Define content blocks

[](#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](https://book.cakephp.org/phinx/0/en/seeding.html).

Here is an **example** seed to create one content block of each type (`html`, `text`, and `image`):

```
