2017 © Pedro Peláez
 

silverstripe-module widgets

Alternative Widgets Module

image

zucchi/widgets

Alternative Widgets Module

  • Wednesday, January 6, 2016
  • by mattcockayne
  • Repository
  • 2 Watchers
  • 0 Stars
  • 16 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Silverstripe-Widgets

Alternative Widgets Module., (*1)

This module was inspired by a number of other guides and modules that are out their that will provide widget type functionality., (*2)

While its not a pretty or fully featured as the silverstripe/widgts module it allows you to use ANY type of form element as part of the widget which is not currently possible with the silverstripe widgets module (try using an UploadField in a widget), (*3)

N.B. Please note that this module does not currently handle requests for forms used in widgets. However this is a feature we hope to add in the future, (*4)

Configuration

This module is Extension based and as such you will need to configure it to work with your silverstripe site., (*5)

In order to do this you can register the extension against your selected page by adding something like the following to your yaml config, (*6)

Page:
  extensions:
    - WidgetPageExtension

This will attach a Single Relationship to Widgets. This essentially acts as a SideBar/WidgetArea and will automatically update the pages CMS fields., (*7)

If you wish to have more than one Widget area on a page you can do this by just manually defining a new $many_many relationship to Widget and adding the appropriate fields to your pages getCMSFields() method. For inspiration take a look at the code/WidgetPageExtension.php file, (*8)

Creating Widgets

While we anticipate providing some default widgets in the future that can be used with this module it is super simple to actually create a new widget. Below are the bare minimum instructions to create a widget, (*9)

  1. Create yourself a folder for your widget
  2. Create an empty _config.php in your new folder
  3. Create a {WidgetName}.php file in your folder that contains the class class {WidgetName} extends Widget {}
  4. Create a {WidgetName}.ss file in your folder with the required template you need for your widget

In your new php class you can define the fields and a getCMSFields() method in the same way you would any other DataObject, (*10)

Rendering

Each Widget relies on having a .ss file which is used in conjunction with a Widget::forTemplate() method., (*11)

There is also helper method that you can use in your template of $GetWidgets which will return your Widgets according to the sort order defined by your GridField., (*12)

The easiest way to render your widgets is to do the following, (*13)

<% loop $GetWidgets() %>
    {$forTemplate}
<% end_loop %>

The Versions

06/01 2016

dev-master

9999999-dev

Alternative Widgets Module

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe widgets