Shows a preview of your dataobjects like the one you get for pages.

Installs: 8 074

Dependents: 1

Suggesters: 0

Security: 0

Stars: 4

Watchers: 9

Forks: 3

Open Issues: 2


2.0.2 2021-01-06 12:06 UTC

This package is auto-updated.

Last update: 2024-06-25 16:22:57 UTC


Dataobject preview

Latest Stable Version Total Downloads

Shows a preview of your dataobjects like the one you get for pages. Works for GridField and ModelAdmin. Works only for Versioned DataObjects.

For the preview to work you need to implement the CMSPreviewable interface on your DataObject and declare the methods getMimeType, CMSEditLink and PreviewLink($action = null).

You also will need to declare the stages this DataObject should show in the preview pane by setting the appropiate static variables to true.

PreviewLink is the only link we are interested for the preview to work. The DataObjectPreviewController will listen for this links to render your MyDataObject with the template in your theme/templates/* folder.

Since activating this feature is a bit hacky, we need to also define a custom template for our CustomModelAdmin.


SilverStripe CMS ^4.0

For a SilverStripe 3.x compatible version of this module, please see the 1 branch, or 1.x release line.


composer require arillo/silverstripe-dataobject-preview:2.0.*


namespace Arillo\DataObjectPreview\Models;

use SilverStripe\ORM\CMSPreviewable;
use SilverStripe\ORM\DataObject;

class MyDataObject extends DataObject implements CMSPreviewable

    private static $show_stage_link = true;
    private static $show_live_link = true;

    private static $extensions = array(

    private static $versioning = array(
        "Stage",  "Live"

    public function PreviewLink($action = null){
        return Controller::join_links(Director::baseURL(), 'cms-preview', 'show', urlencode($this->ClassName), $this->ID);

    public function getMimeType()
        return 'text/html';

    public function CMSEditLink(){

If our CustomModelAdmin looks like this:

namespace Arillo\DataObjectPreview\Admins;

use Arillo\DataObjectPreview\Models\MyDataObject;

class CustomModelAdmin extends ModelAdmin {
    private static $managed_models = array (

We need to create the corresponding template in mysite/templates/Arillo/DataObjectPreview/Admins/Includes/ with this content copied from version 4.7.0 of the silverstripe/cms module. (Beware that this can vary depending on the version and may be changed over time.)

    class="cms-preview fill-height flexbox-area-grow"
    <div class="panel flexbox-area-grow fill-height">
        <div class="preview-note">
            <span><!-- --></span><%t
            'Website preview' %>
        <div class="preview__device">
            <div class="preview-device-outer">
                <div class="preview-device-inner">
        class="toolbar toolbar--south cms-content-controls cms-preview-controls"
    <div class="cms-preview-overlay ui-widget-overlay-light"></div>


By default, the dataobject preview will look for templates with the dataobject classname directly in the templates folder. So for the example above it will look for themes/yourtheme/templates/Arillo/DataObjectPreview/Models/ If you would like to customise this behaviour you can do so by implementing your own renderPreview method on the DataObject.

namespace Arillo\DataObjectPreview\Models;
class MyDataObject extends DataObject implements CMSPreviewable
    public function renderPreview()
        // this will look for themes/yourtheme/templates/Arillo/DataObjectPreview/Models/
        return $this->renderWith(MyDataObject::class);

You can overwrite the main template by placing it either in themes/yourtheme/templates/ or mysite/

  • -> Container for MyDataObject preview (Like the main

Since SilverStripe 4.11 supports better previews for DataObject, you might want to disable legacy code injection by this module. It can be turned off by:

  inject_legacy_code: false

Tip: If you are using silverstripe-gridfield-betterbuttons you can disable the dataobject preview links since they are no longer needed. Just add this to your config.yml.

    BetterButtonFrontendLinksAction: false
    BetterButtonFrontendLinksAction: false


V 2.0.2

  • added modeladmin support

V 2.0.0

  • renamed method previewRender to renderPreview