2017 © Pedro Peláez
 

silverstripe-vendormodule silverstripe-block-page

A modular approach to building pages in SilverStripe

image

cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  • Monday, March 12, 2018
  • by cyber-duck
  • Repository
  • 3 Watchers
  • 13 Stars
  • 1,876 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 22 Versions
  • 18 % Grown

The README.md

SilverStripe 4 Block Page

Latest Stable Version Latest Unstable Version Total Downloads License, (*1)

Author: Andrew Mc Cormack, (*2)

Features

A modular approach to building pages in SilverStripe which allows model based page components. - Custom model based blocks - No limit to number of blocks - Easily block selection and editing - Use drag and drop GridField functionality to change and re-order blocks easily - Apply complex logic like forms to blocks - Versioning across blocks, (*3)

Screen Shots

Installation

Add the following to your composer.json file and run /dev/buid?flush=all, (*4)

{  
    "require": {  
        "cyber-duck/silverstripe-block-page": "4.0.*"
    }
}

Setup

Add Extension and Template Loop

The first step to adding block functionality is to apply the block page extension to your DataObject. This can be a normal DataObject or a Page., (*5)

Page:
  extensions:
    - BlockPageExtension

This will add a new tab to the CMS called content blocks. The second step is to apply the loop within your template for the blocks:, (*6)

<% loop ContentBlocks %>
$Template
<% end_loop %>

Add Block Model and Template

The next step is to create a block. A block consists of 2 parts; a DataObject and a .ss template. Both these should have the same name., (*7)

  • EditorBlock.php
  • EditorBlock.ss

The model file can reside anywhere inside your code folder and should extend ContentBlock The base template for a block DataObject is as follows:, (*8)

use CyberDuck\BlockPage\Model\ContentBlock;
use SilverStripe\Forms\HeaderField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;

class EditorBlock extends ContentBlock
{
    private static $singular_name = 'Editor';

    private static $description = 'Simple WYSIWYG editor block';

    private static $preview = '/themes/{YourTheme}/img/block/EditorBlock.png';

    private static $db = [
        'Content' => 'HTMLText'
    ];

    public function getCMSFields()
    {
        $fields = parent::getCMSFields();

        # HEADER - THIS FIELD IS REQUIRED
        $fields->insertBefore(HeaderField::create('BlockHeader', self::i18n_singular_name()), 'Title')

        # FIELDS - YOUR FIELDS HERE
        $fields->addFieldToTab('Root.Main', HTMLEditorField::create('Content')); // example field

        return $fields;
    }
}

In the example above 1 custom block field is created called Content. You can replace this / add any other fields you want. There are 3 config properties used for a block used in the block selection screen:, (*9)

  • $singular_name - Block title
  • $description - Block description
  • $preview - Preview image for the block. You can point this to an image folder in your theme or similar. 360w x 150h.

Next in your theme folder create a folder at themes/{YourTheme}/templates/Block/ and add the EditorBlock.ss template within with the following content:, (*10)

<div>
    $Content
</div>

Add Block YML Config

The final step to configuring your blocks is to set up the block YML config:, (*11)

---
Name: block config
---
CyberDuck\BlockPage\Model\ContentBlock:
  blocks:
    - EditorBlock
  restrict:

Visit /dev/build?flush=all, (*12)

Add Blocks in the CMS

Go the the CMS and visit your Page / Object editing screen and you will see a new tab called Content Blocks. Here you can create new blocks, edit blocks, and re-order blocks., (*13)


Extra Config

Restricting Blocks

You can restrict certain block selections to a particular page type by passing a restrict option, (*14)

CyberDuck\BlockPage\Model\ContentBlock:
  blocks:
    - EditorBlock
    - HomeFeaturedBlock
  restrict:
    HomePage:
      - HomeFeaturedBlock

Creating a Block Holder Template

If you wish to wrap all blocks within a certain template you can create a ContentBlock_holder.ss template within the /Block/ folder., (*15)

<div id="block-$ID">
    $Template
</div>

The loop within your page needs to change slightly and call $TemplateHolder instead of template., (*16)

<% loop ContentBlocks %>
$TemplateHolder
<% end_loop %>

Todo

The Versions

12/03 2018

dev-master

9999999-dev http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

  • php >=5.6

 

page silverstripe modular page block page silverstripe 4

12/03 2018

dev-develop

dev-develop http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

  • php >=5.6

 

page silverstripe modular page block page silverstripe 4

12/03 2018

4.1.1

4.1.1.0 http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

  • php >=5.6

 

page silverstripe modular page block page silverstripe 4

13/02 2018

4.1.0

4.1.0.0 http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

  • php >=5.6

 

page silverstripe modular page block page silverstripe 4

22/11 2017

4.0.2

4.0.2.0 http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

  • php >=5.6

 

page silverstripe modular page block page silverstripe 4

22/11 2017

4.0.x-dev

4.0.9999999.9999999-dev http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

  • php >=5.6

 

page silverstripe modular page block page silverstripe 4

10/11 2017

4.0.1

4.0.1.0 http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

 

page silverstripe modular page block page silverstripe 4

26/10 2017

4.0.0

4.0.0.0 http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

 

page silverstripe modular page block page silverstripe 4

15/09 2017

1.1.3

1.1.3.0 http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

 

page silverstripe modular page block page

15/09 2017

3.x-dev

3.9999999.9999999.9999999-dev http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

 

page silverstripe modular page block page

09/03 2017

1.1.2

1.1.2.0 http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

 

page silverstripe modular page block page

07/03 2017

dev-duplicate-method

dev-duplicate-method http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

 

page silverstripe modular page block page

13/02 2017

1.1.1

1.1.1.0 http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

 

page silverstripe modular page block page

31/01 2017

1.1.0

1.1.0.0 http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

 

page silverstripe modular page block page

05/01 2017

1.0.7

1.0.7.0 http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

 

page silverstripe modular page block page

08/12 2016

1.0.6

1.0.6.0 http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

 

page silverstripe modular page block page

05/12 2016

1.0.5

1.0.5.0 http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

 

page silverstripe modular page block page

05/12 2016

1.0.4

1.0.4.0 http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

The Requires

 

page silverstripe modular page block page

02/12 2016

1.0.3

1.0.3.0 http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

page silverstripe modular page block page

29/11 2016

1.0.2

1.0.2.0 http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

page silverstripe modular page block page

29/11 2016

1.0.1

1.0.1.0 http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

page silverstripe modular page block page

24/11 2016

1.0.0

1.0.0.0 http://github.com/cyber-duck/silverstripe-block-page

A modular approach to building pages in SilverStripe

  Sources   Download

MIT

page silverstripe modular page block page