PHPackages                             heyday/silverstripe-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. [Templating &amp; Views](/categories/templating)
4. /
5. heyday/silverstripe-slices

ActiveSilverstripe-vendormodule[Templating &amp; Views](/categories/templating)

heyday/silverstripe-slices
==========================

Provides a Slice extension to DataObject subclasses with custom templates

3.1.0(1mo ago)73.3k3MITPHP

Since Nov 19Pushed 2mo ago22 watchersCompare

[ Source](https://github.com/WPP-Public/akqa-nz-silverstripe-slices)[ Packagist](https://packagist.org/packages/heyday/silverstripe-slices)[ RSS](/packages/heyday-silverstripe-slices/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (4)Versions (19)Used By (0)

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

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

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

- [Usage](#usage)
    - [Templates](#templates)
    - [Adding Slices to Page](#adding-slices-to-page)
    - [Subclassing Slice](#subclassing-slice)
    - [Using Slices on a sub class of a Page/SiteTree](#using-slices-on-a-sub-class-of-a-pagesitetree)
    - [Customising CMS fields](#customising-cms-fields)
- [Example config](#example-config)
- [Compatibility](#compatibility)

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 should go in `themes/[theme]/templates/[MyProject]/DataObjects/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:
    - Heyday\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:

```
