toastnz/blocks-layouts

Silverstripe content blocks module

Installs: 4 118

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 4

Forks: 0

Open Issues: 0

Type:silverstripe-vendormodule


README

Simple content blocks system. Nothing fancy, easy to implement.

Requirements

See composer.json

Installation

Add the following to your config.yml (optional):

PageController:
  extensions:
    - Toast\Blocks\Extensions\PageControllerExtension

Use Page or other class that extends SiteTree.

In your Layout/Page.ss template, add the following:

<% loop $ContentBlocks %>
    $ForTemplate
<% end_loop %>

Configuration

Add / remove available block classes

Toast\Blocks\Extensions\PageExtension
  available_blocks:
    - Toast\Blocks\TextBlock

Add / remove available alternate block layouts

"layout_src": directory that holds folders of different layouts with .ss templates "layout_icon_src": directory that holds all the layout icons "layout_dist_dir": specificed the css for block layouts

CSS file will only be included with the syntax of 'theme/themename/dist/styles/$LayoutName-$BlockType.css"

Toast\Blocks\Extensions\PageExtension:
  layout_src: 'app/templates/Toast/Blocks'
  layout_icon_src: 'app/client/images/layout-icons'
  layout_dist_dir: 'theme/themename/dist/styles'
  

Ensure there are at least one CustomBlock.ss and 'customblock.svg' icon in each of the specified directory. Layout will be available for all subsites.

.ss template naming

You may have multiple layouts, please ensure you have the block.ss created under a new layout folder in the src directory.
e.g. 'app/templates/Toast/Blocks/CustomLayoutNameOne/ImageBlock.ss' or 'app/templates/Toast/Blocks/CustomLayoutNameTwo/ImageBlock.ss'

Layout icon naming:

Please ensure the layout icon are named after the block name are all in lowercase, e.g. customblock.svg.
e.g. 'app/client/images/layout-icons/customlayoutone/customblock.svg' or 'app/templates/Toast/Blocks/customlayouttwo/customblock.svg'

Icon extensions

Allowed extension: 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg'

Create a custom block

Extend Block to create a new block type.

<?php
 

class MyBlock extends Toast\Blocks\Block
{
    private static $singular_name = 'My Block';
    private static $plural_name = 'My Blocks';
    private static $icon = 'mysite/images/blocks/custom.png';
    
    private static $db = [
        'Content' => 'HTMLText'
    ];

}

/themes/default/templates/Toast/Blocks/MyBlock.ss:

<%-- Your block template here --%>

<h2>$Title</h2>
$Content

Todo: