dev-master
9999999-dev http://github.com/gorriecoe/silverstripe-previewAdds a preview options to a Dataobject.
BSD-3-Clause
The Requires
by Gorrie Coe
silverstripe modular
Adds a preview options to a Dataobject.
Adds preview options to a Dataobject or SiteTree. Basically provides more advanced options to summary content., (*1)
Composer is the recommended way of installing SilverStripe modules., (*2)
composer require gorriecoe/silverstripe-preview
Adding preview to a DataObject, (*3)
MyDataObject: extensions: - gorriecoe\Preview\Extensions\Previewable
Note that Previewable automatically extends SiteTree, (*4)
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)
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)
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 %>
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)
Adds a preview options to a Dataobject.
BSD-3-Clause
silverstripe modular