2017 © Pedro Peláez
 

silverstripe-vendormodule silverstripe-preview

Adds a preview options to a Dataobject.

image

gorriecoe/silverstripe-preview

Adds a preview options to a Dataobject.

  • Tuesday, June 19, 2018
  • by gorriecoe
  • Repository
  • 2 Watchers
  • 1 Stars
  • 30 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 131 % Grown

The README.md

Silverstripe preview

Adds preview options to a Dataobject or SiteTree. Basically provides more advanced options to summary content., (*1)

Installation

Composer is the recommended way of installing SilverStripe modules., (*2)

composer require gorriecoe/silverstripe-preview

Requirements

  • silverstripe/cms ^4.0

Suggestion

Maintainers

Usage

Adding preview to a DataObject, (*3)

MyDataObject:
  extensions:
    - gorriecoe\Preview\Extensions\Previewable

Note that Previewable automatically extends SiteTree, (*4)

Default preview fields

Adding default fields to a DataObject or SiteTree, (*5)

SilverStripe\CMS\Model\SiteTree:
  extensions:
    - gorriecoe\Preview\Extensions\PreviewDefaultFields

This will add Image, Title, Content and Label fields to a summary tab., (*6)

Defining your own preview data

By default preview data will inherit from the DataObject. For example $MyDataObject.Preview.Image will use $MyDataObject.Image. However if you want the preview image to have fallback options, you can define it in your DataObject with the following static variable define., (*7)

class MyDataObject extends DataObject
{
    private static $has_one = [
        'PreviewImage' => Image::class,
        'HeaderImage' => Image::class
    ];

    private static $preview_data = [
        'Image' => [
            'PreviewImage',
            'HeaderImage'
        ]
    ];
}

In the example above $MyDataObject.Preview.Image will return the Image from PreviewImage first, if that doesn't exist then return HeaderImage and finally if that doesn't exist then return null., (*8)

Template

Access preview data via template simply change the scope of the data using one of the following methods., (*9)

<% loop MyDataObjects %>
    <h2>
        {$Preview.Title}
    </h2>
<% end_loop %>
<% loop MyDataObjects %>
    <% with Preview %>
        <h2>
            {$Title}
        </h2>
    <% end_with %>
<% end_loop %>

Advanced Usage

Check out silverstripe/silverstripe-action code for an example of advanced usage. In it you will see you can prepend additional fallback options from another dataobject., (*10)

The Versions

19/06 2018

dev-master

9999999-dev http://github.com/gorriecoe/silverstripe-preview

Adds a preview options to a Dataobject.

  Sources   Download

BSD-3-Clause

The Requires

 

by Gorrie Coe

silverstripe modular