PHPackages                             sunnysideup/slices - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. sunnysideup/slices

ActiveSilverstripe-vendormodule

sunnysideup/slices
==================

Provides a Slice extension to DataObject subclasses with custom templates

1.0.0(2y ago)020MITPHP

Since Nov 19Pushed 2y agoCompare

[ Source](https://github.com/sunnysideup/silverstripe-slices)[ Packagist](https://packagist.org/packages/sunnysideup/slices)[ RSS](/packages/sunnysideup-slices/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (15)Versions (14)Used By (0)

Content Slices for SilverStripe
===============================

[](#content-slices-for-silverstripe)

Content management in "slices"; separate content components, each with their own template, fields and visual settings that can be created and arranged by a user in the CMS.

- Slice previews in the CMS
- Slice CMS configured via YAML

Usage
-----

[](#usage)

It's best to use silverstripe-slices with lots of generic fields on the base slice class, since this allows templates to share fields and be configured in YAML without creating a class for each slice. [silverstripe-adaptivecontent](https://github.com/heyday/silverstripe-adaptivecontent) works well for this (and used to be integrated with this module).

```
# Use the generic fields in silverstripe-adaptivecontent
Slice:
  extensions:
    - 'AdaptiveContent'
    - "AdaptiveContentRelated('Page')"
```

### Templates

[](#templates)

Each slice type/template has it's own template file with the name `[BaseSliceClass]_[TemplateName]`. These can go in `themes/[theme]/templates/Slices` to separate them from the other templates in your site.

### Adding Slices to Page

[](#adding-slices-to-page)

This module comes with an extension for easily setting up Slices on Page:

```
Page:
  extensions:
    - PageSlicesExtension
```

In templates, all slices can be rendered using this:

```

        $forTemplate

```

### Subclassing Slice

[](#subclassing-slice)

Subclassing `Slice` is a normal use case, however note that when subclassing it, you'll need to override the method `getBaseSliceClass` method in your "base" slice subclass (the one you point to in a has\_many from Page) for the slice to save correctly:

```
class ContentSlice extends Slice
{
    protected function getBaseSliceClass()
    {
        return __CLASS__;
    }
}

class VideoSlice extends ContentSlice
{
    // Subclasses of your 'base' subclass don't need anything special
}
```

This is due to the the module needing a "default" class to fall back to when the `className` key has not been set in a template config.

#### Customising CMS fields

[](#customising-cms-fields)

Adding and modifying fields in `YourBaseSlice::getCMSFields` is an expected use case. Note that things configured in the slices YAML configuration will be overriden if, for example, you replace a field with something custom. In this case, you can re-apply the slices config with the following at the end of your `getCMSFields` function:

```
// Re-apply slices config
$config = $this->getCurrentTemplateConfig();
$this->configureFieldsFromConfig($fields, $config);
```

#### Customising slice previews in the CMS

[](#customising-slice-previews-in-the-cms)

[![Slice preview in CMS](docs/images/dataobject-preview-slice.png)](docs/images/dataobject-preview-slice.png)

A preview of a slice renders the CMS in an iframe when editing and browsing. Out of the box, previews are rendered inside a basic HTML page wrapper: `silverstripe-slices/templates/SliceWrapper.ss`. You can override this wrapper in your own theme to customise how slice previews are delivered.

### Example config

[](#example-config)

```
Slice:

  # Define stylesheets to be used when previewing slices in the CMS
  previewStylesheets:
    - /themes/base/css/styles.css

  # Automatically configure the upload folder for these file fields on Slice
  # Files and images will be uploaded to assets/Uploads/Slices/[TemplateName]
  uploadFolderFields:
    - LeadImage
    - SecondaryImage
    - LeadFile

  # The default slice template can be specified, or defaults to the first defined
  # This is just what is selected by default when a new slice is created
  defaultTemplate: TwoColumnImage

  templates:
    Quote:
      fields:
        Title: Quotee
        Content:
          # Set the CMS "title" of the field
          label: Quote

          # Change the form component used for this field
          fieldClass: TextareaField

          # Cast the field to something when rendering it in the template
          casting: Text

          # Value to use for the field's "right title"
          help: ~20 - 30 words

          # Value to use when previewing what the slice will look like
          exampleValue: Dolor exercitation sint ad minim et deserunt nisi aliquip cillum laboris ipsum esse nulla commodo cupidatat ipsum proident exercitation veniam

      # Options exposed in the CMS for configuring the slice template
      # The key is accessible in templates, and the value is used as the CMS title
      visualOptions:
        no-icon: No icon
        bold-quote: Bold quoted text

    TwoColumnImage:
      # Name to show for the template in the CMS
      name: Two column with image

      # Class to change to when using this template
      # This allows complex slices to have extra fields and code
      className: TwoColumnImageSlice

      # Fields that only need a label configured can be defined using a shortcut:
      # (The order fields are defined here also controls the order they show in the CMS)
      fields:
        Title: ~
        Content: Text column
        LeadImage:
          name: Image
          # Images can be specified as file names in example content
          exampleValue: themes/base/images/examples/random-guy.jpg

      visualOptions:
        image-right: Image in right column
        title-centered: Center title above columns
```

Compatibility
-------------

[](#compatibility)

This module requires at least SilverStripe 3.1 and PHP 5.3.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 80.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~392 days

Recently: every ~682 days

Total

10

Last Release

1019d ago

Major Versions

0.2.1 → 1.0.0-alpha.12015-07-19

1.0.0-alpha.5 → 3.x-dev2019-10-03

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/167154?v=4)[Sunny Side Up](/maintainers/sunnysideup)[@sunnysideup](https://github.com/sunnysideup)

---

Top Contributors

[![stecman](https://avatars.githubusercontent.com/u/2230769?v=4)](https://github.com/stecman "stecman (33 commits)")[![sunnysideup](https://avatars.githubusercontent.com/u/167154?v=4)](https://github.com/sunnysideup "sunnysideup (3 commits)")[![b-rhodes](https://avatars.githubusercontent.com/u/25066797?v=4)](https://github.com/b-rhodes "b-rhodes (2 commits)")[![camspiers](https://avatars.githubusercontent.com/u/51294?v=4)](https://github.com/camspiers "camspiers (2 commits)")[![barrykeenan](https://avatars.githubusercontent.com/u/395529?v=4)](https://github.com/barrykeenan "barrykeenan (1 commits)")

### Embed Badge

![Health badge](/badges/sunnysideup-slices/health.svg)

```
[![Health](https://phpackages.com/badges/sunnysideup-slices/health.svg)](https://phpackages.com/packages/sunnysideup-slices)
```

###  Alternatives

[silverstripe/cms

The SilverStripe Content Management System

5163.4M1.3k](/packages/silverstripe-cms)[silverstripe/recipe-cms

SilverStripe recipe for fully featured page and asset content editing

212.4M184](/packages/silverstripe-recipe-cms)[dnadesign/silverstripe-elemental

Elemental pagetype and collection of Elements

1151.0M254](/packages/dnadesign-silverstripe-elemental)[silverstripe/subsites

Run multiple sites from a single SilverStripe install.

65392.9k20](/packages/silverstripe-subsites)[silvershop/core

Provides an ecommerce product catalog, shopping cart, and order management system

11340.0k37](/packages/silvershop-core)[symbiote/silverstripe-advancedworkflow

Adds configurable workflow support to the CMS, with a GUI for creating custom workflow definitions.

46295.2k7](/packages/symbiote-silverstripe-advancedworkflow)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
