Website/Silverstripe

We currently use Silverstripe for some of our Website infrastructure.

Setting up a local development environment
These instructions describe setting up a local development environment for Silverstripe on Linux using the Pod Manager tool (Podman). Podman allows running containers without a daemon and without root privileges. Podman is compatible with Docker. The information is adapted from Podman's rootless tutorial.

Install podman, podman-compose, slirp4netns, fuse-overlayfs and crun.

Make sure you are using v2 cgroups. Consult documentation for your Linux distribution of choice regarding this topic.

Create the subuid and subgid files:

Create the configuration to use crun as the OCI (Open Container Initiative) runtime:

Give the command:

Verify that you see
 * CgroupVersion: v2
 * OCIRuntime: name: crun
 * GraphDriverName: overlay

Create docker-compose.yml:

The volume declarations map local directories and files to locations inside the containers.

In the directory with the docker-compose-yml:

Note:  matches the name of the database service in docker-compose.yml

Change into the silverstripe directory and grab composer:

In the directory with docker-compose.yml, give this command to create and start the containers:

Show the running containers:

Copy the Silverstripe container ID from the output of the previous command and enter the container like so:

Exit container with.

Create a file called  in the directory silverstripe/libreoffice:

SS_TRUSTED_PROXY_IPS="*" SS_DATABASE_CLASS="MySQLDatabase" SS_DATABASE_NAME="silverstripe" SS_DATABASE_SERVER="mariadb" SS_DATABASE_USERNAME="silverstripe" SS_DATABASE_PASSWORD="password" SS_DEFAULT_ADMIN_USERNAME="admin" SS_DEFAULT_ADMIN_PASSWORD="password" SS_ENVIRONMENT_TYPE="dev"

Build the Silverstripe database by navigating to this address in your web browser: http://localhost:8080/libreoffice/dev/build

Now you can access your local site at http://localhost:8080/libreoffice/ and the admin interface at http://localhost:8080/libreoffice/admin/

To stop the containers:

To start them again:

For help:

The container data is stored under

Theme structure
Silverstripe supports having multiple themes per site. If there is no need for this, everything is a bit simpler and the directory structure can be laid out like so: public/ css/ images/ javascript/ app/ _config/ code/ templates/ Includes/ Layout/

The file app/_config/theme.yml can simply have this content:

Every time you modify one of the .yml files or create new .ss files, you need to flush the cache by visiting http://localhost:8080/libreoffice/public/?flush

Page types
You can have many page types. You can name them anything you like and Silverstripe associates the model, controller and view files based on the naming.
 * is conventionally the model, having things like database field definitions and functions that can be used in templates.
 * is the controller and does stuff that has to do with requests such as database queries, form submission and authentication.
 * is the view, the template associated with the page type.

The page types typically extend the Page and PageController classes.

Every time you create a new page type, you have to rebuild the database. You can rebuild the database and flush the cache at the same time by visiting http://localhost:8080/libreoffice/dev/build?flush

You can change the type of a certain page in the admin editor view by clicking on the Settings tab and using the Page type dropdown.

Page types are explained in the Silverstripe lessons The holder/page pattern and Working with multiple templates.

Templates
Silverstripe uses its own templating language instead of plain old PHP. This makes things a bit more complicated and you have to be careful to skip outdated information, when doing web searches.

Some common things:
 * will make Silverstripe look for  inside the   directory and include its contents to be rendered
 * will include the contents of . If there is no separate layout file for the extended page type, it will include the contents of

Including assets
Instead of putting your CSS and JS includes inside the .ss files, it is advised to use the Requirements class inside the page controller.

In the page controller you would have:

There are some things that you must include in the .ss files themselves. In these cases, you benefit from using the baseURL variable to preserve portability regarding paths. Example:

Note that this time public/ is left out of the path.

Creating custom content fields
Silverstripe does not have functionality for creating new fields inside the admin interface unlike some other CMS applications. Everything has to be done through a somewhat tedious process of editing files and rebuilding the database. This is explained in a Silverstripe lesson.

An example of an imaginary  defining custom fields:

After rebuilding the dabase, you would be able to use the fields in the admin and include their contents via the .ss files by referring to them by their name such as.