Manage site-wide modules (aka widgets) and select the pages on which they are to appear. This allows you to repurpose content across your website, and build easily modular content elements.
- SilverStripe 3.1
- SilverStripe GridFieldExtensions module (
https://github.com/ajshort/silverstripe-gridfieldextensions)
For a Silverstripe CMS 4.x compatible version of this module, please see the master branch, please see the 3.x or 4.x release line.
For a Silverstripe CMS 3.x compatible version of this module, please see the 3 branch, or 2.x release line.
- Clone this repository into your root folder (ie
public_html/module-manager) - Run /dev/build?flush=1
- Load your Module Positions
- Insert your Module Positions in your template (ie
$ModuleArea(footer))
- Edit your
mysite/_config/config.ymlfile to add any additional module areas. Use the following format:
ModuleManager:
positions:
- 'module-name-here'
- In your template, use the code
$ModulePosition(alias)where alias is your position's alias string. - Flush your template cache (
?flush=all)
- Within the Module Manager admin, create a new
Moduleobject. The type dropdown will show the list of available module types. - Assign your new
Moduleobject to theModulePositionobject you created earlier.
- Create a new DataObject file
mysite/code/Modules/MyModule.php:
<?php
class MyModule extends Module {
// set module names
private static $singular_name = 'My Module';
private static $plural_name = 'My Modules';
private static $description = 'This is my great custom module';
// your custom fields
static $db = array(
'CustomField' => 'Text'
);
// create cms fields
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', TextField::create('CustomField', 'My Custom Field'));
return $fields;
}
}
- Create your template file
themes/mytheme/Modules/MyModule.ss:
<div class="module-item my-custom-module">
<h3>$Title</h3>
<div class="module-content">
$Content
$CustomField
</div>
</div>
- Perform a build and flush (
/dev/build?flush=all) - Now you can create your custom module type
To avoid having to set a module on each page within a section, you can set your pages to inherit it's parent page's modules.
- Open your page, and navigate to the Modules tab
- Check Inherit Modules and Save your page.
- You can apply this inheritance further up the page hierarchy if required.