Display announcement messages for SilverStripe

Installs: 392

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0


dev-master / 0.1.x-dev 2018-07-30 01:41 UTC

This package is not auto-updated.

Last update: 2021-01-09 09:50:44 UTC


Announce things to the page controller & view in SilverStripe. Can be used to power plain messages, modals, alerts, and callouts.

Multiple announcements can be stacked.

Announcements can be templated to match component libraries such as Bootstrap.


Note: For a similar module in SilverStripe 3, consider using axyr/silverstripe-flashmessage


  • SilverStripe >= 4.0
  • PHP >= 5.6


composer require jakxnz/silverstripe-announce


dev/build?flush=all your SilverStripe project.


Create announcements with Titles, Headings, Contents, Footers and Actions. Control whether they should be stored for later responses. Control whether they should be dismissable.

Announcements are retained at StilverStripe's Controller, and stored in the Announcement store (default is $_SESSION).

Each announcement is made available to the view via a SilverStripe Controller extension.

Only one set of announcements can be stacked at a time.

The announcement store can be replaced with a custom class that implements AnnouncementStoreInterface;


Queue a new announcement

Announcements::queue('AnnouncementName', 'Announcement Title', 'This is an announcement message');

Accounments::queue() will accept all arguements for an Announcement

Queue an existing announcement

$msg = Announcement::create('AnnouncementName', 'Announcement Title', 'This is an announcement message');


Get all current announcements

$announcements = Announcements::get();

Get an announcement by name


Get an announcement by type


Clear the announcements queue


Display announcements in the top scope of a template

<% if $Announcements %>
<% end_if %>

Customise an announcement

Example of all options

use CodeCraft\Announce\Model\Announcement;
use CodeCraft\Announce\Model\Action;


$announcement = Announcement::create(
    $name = 'AnnouncementName',
    $title = 'Announcement Title',
    $content = 'A plain or html string',
    $heading = 'A plain or html string',
    $footer = 'A plain or html string',
    $actions = [
            $name = 'ActionName',
            $content = 'A plain or html string',
            $type = Action::BUTTON,
            $link = 'https://www.google.com/',
            $extraClass = 'btn btn-primary'
    $type = Announcement::DEFAULT
    // Store announcement

    // Dismissable

    // Name

    // Title
    ->setTitle('Announcement Title')
    ->setTitle('<p>Announcement Title</p>')

    // Content
    ->setContent('Announcement body')
    ->setContent('<p>Announcement body</p>')

    // Heading
    ->setHeading('Announcement heading')
    ->setHeading('<p>Announcement heading</p>')

    // Footer
    ->setFooter('Announcement footer')
    ->setFooter('<p>Announcement footer</p>')

    // Action
            ->addExtraClass('btn btn-primary')
            ->setAttribute('title', 'A helpful title')

    // Type

    // Template

Announcement store

Access the announcement store


Expect announcements to be stored as an array

Set storable

Announcements are stored by default, so that they can be included in the next relevant response.

Define if the announcement should be stored

$msg = Announcement::create('AnnouncementName', 'Un-stored Announcement', 'This announcement is not stored')

Custom announcement template

Set a custom template for all announcements by overloading templates

Set a custom template for any announcement

$msg = Announcement::create('AnnouncementName', 'Announcement Title', 'This is an announcement message')

Overloading templates

Announcement template

Overload the default template for all announcement actions by overloading templates/CodeCraft/Announce/Model/Announcement

Announcement Action template

Overload the default template for all announcement actions by overloading templates/CodeCraft/Announce/Model/Action

Read more about SilverStripe Template Inheritance

Announcements by name

Each announcement name is distinct. Call announcements by name





Announcements by type

Set any announcement's type with one of the available types; Announcement::DEFAULT, Announcement::MODAL, Announcement::TRAY, Announcement::MESSAGE, or Announcement::CALLOUT.

$msg = Announcement::create('Name')->setType(Announcement::MODAL);

Call announcements by type





Can be 'default', 'modal', 'tray', 'message', 'callout'


  • Does not have any CMS editable functionality


Modified BSD License

Copyright (c) 2018, Jackson Darlow

Read the license

To do

  • Tests
  • Add redundancies for cases where announcement store is ahead of announcement stack
  • Add a way to disable the store
  • Create a database announcement store
  • Create a redis announcement store
  • Replace Announcement type constants with an object-oriented model
    • Create an email Announcement type
  • An announcement history for user-focused announcements
    • Flag announcement when viewed by user
  • Add CMS editable announcements, similiar to nzta/silverstripe-sitebanner
  • Version CMS editable announcements