Simple content blocks system. Nothing fancy, easy to implement.
See composer.json
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 %>
Toast\Blocks\Extensions\PageExtension
available_blocks:
- Toast\Blocks\TextBlock
"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.
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'
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'
Allowed extension: 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg'
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