Create custom page CMS
August 7, 2025 · AI Conversations
—
### ✅ 1. **Create the Page Type (Model)**
Create a PHP file named `CustomPage.php` inside `app/src/PageTypes/` or `app/src/Pages/` (depends on your folder structure).
<?php
namespace AppPages;
use SilverStripeCMSModelSiteTree;
use SilverStripeFormsFieldList;
use SilverStripeFormsTextareaField;
use SilverStripeORMDB;
class CustomPage extends SiteTree
{
private static $table_name = 'CustomPage';
private static $db = [
'IntroText' => 'Text',
];
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', TextareaField::create('IntroText', 'Introduction Text'));
return $fields;
}
}
—
### ✅ 2. **Create the Controller**
Create a corresponding controller `CustomPageController.php` in the same or `app/src/Controllers/` folder.
<?php
namespace AppPages;
use PageController;
class CustomPageController extends PageController
{
private static $allowed_actions = [
'test'
];
public function test()
{
return 'This is a test action';
}
protected function init()
{
parent::init();
// Custom initialization logic if needed
}
}
—
### ✅ 3. **Create the Template**
Create the template file:
themes/YOUR_THEME/templates/App/Pages/CustomPage.ss
<% include Layout/Header %>
<h1>$Title</h1>
<p>$IntroText</p>
<% include Layout/Footer %>
> Replace `YOUR_THEME` with your active theme (check `app/_config/theme.yml` if unsure).
—
### ✅ 4. **Run dev/build**
Run the following command in browser or CLI:
http://localhost/dev/build?flush
Or via CLI:
vendor/bin/sake dev/build flush=all
—
### ✅ 5. **Create the Page in CMS**
– Go to the **Silverstripe admin** panel (`/admin`)
– Click **Pages > Add new**
– Choose **Custom Page**
– Publish it
Now this page is fully manageable via CMS, with custom controller and database field support.
—
If you'd like this to be in a **different namespace**, or need to make this available as a **custom route (non-SiteTree)**, let me know — I’ll guide you through that variant too.
—
### ✅ Step 1: Create the Page Class
Create `CustomPage.php` in `app/src/Pages/`:
<?php
namespace AppPages;
use SilverStripeCMSModelSiteTree;
class CustomPage extends SiteTree
{
private static $table_name = 'CustomPage';
// Add DB fields if needed later
}
—
### ✅ Step 2: Create the Page Controller
Create `CustomPageController.php` in the same folder:
<?php
namespace AppPages;
use PageController;
class CustomPageController extends PageController
{
// Optional: add allowed actions or custom logic
}
—
### ✅ Step 3: Create the Template
Create the template file at:
themes/YOUR_THEME/templates/App/Pages/CustomPage.ss
<% include Layout/Header %>
<h1>$Title</h1>
<% include Layout/Footer %>
—
### ✅ Step 4: Run dev/build
Visit:
http://your-site.dev/dev/build?flush
or run in terminal:
vendor/bin/sake dev/build flush=all
—
### ✅ Step 5: Create the Page in CMS
– Log in to `/admin`
– Click “Pages” > “Add new”
– Select “Custom Page”
– Fill in the title/content
– Publish the page
—
You're done! Your custom page is now available and manageable via the CMS.
—
### ✅ Step 1: Create `CustomPage.php` in `app/src/`
<?php
namespace App;
use SilverStripeCMSModelSiteTree;
class CustomPage extends SiteTree
{
private static $table_name = 'CustomPage';
// Add CMS fields or DB fields if needed later
}
—
### ✅ Step 2: Create `CustomPageController.php` in `app/src/`
<?php
namespace App;
use PageController;
class CustomPageController extends PageController
{
// You can add allowed_actions or custom methods here
}
—
### ✅ Step 3: Create the Template
Create this file:
themes/YOUR_THEME/templates/App/CustomPage.ss
With basic content:
<% include Layout/Header %>
<h1>$Title</h1>
<% include Layout/Footer %>
> Make sure the folder structure inside `templates` matches your PHP namespace.
—
### ✅ Step 4: Run dev/build
In the browser:
/dev/build?flush
Or via terminal:
vendor/bin/sake dev/build flush=all
—
### ✅ Step 5: Add Page in CMS
– Go to `/admin`
– Add a new page → Select **Custom Page**
– Publish
—
Now your custom page is ready and editable via CMS!
If you'd prefer to organize under `app/src/Pages/`, that's also acceptable — Silverstripe resolves by namespace, not folder name.
—
### ✅ Here's how it works:
#### 1. **You add a page in the CMS:**
– Go to `/admin`
– Click "Pages" > "Add new"
– Select `Custom Page`
– Set **Title**: e.g., `My Custom Page`
– Set **URL Segment**: e.g., `my-custom-page`
– Click **Publish**
—
#### 2. **Access the page in browser:**
https://yourdomain.com/my-custom-page
—
### 💡 Optional: Accessing a method from the controller
If your `CustomPageController` has custom actions like:
private static $allowed_actions = ['test'];
public function test()
{
return 'This is a test action';
}
Then you can visit:
https://yourdomain.com/my-custom-page/test
> ✅ As long as the page with slug `my-custom-page` exists in CMS, and `test` is in `$allowed_actions`, it will be accessible.
—
Let me know if you want to register a page completely **outside the CMS** using routes instead — that's a different setup.
Custom page
Getting Started
To get started with the SilverStripe framework:
Create a Controller subclass (docs.silverstripe.org/en/developer_guides/controllers/)
Setup the routes.yml to your Controller (docs.silverstripe.org/en/developer_guides/controllers/routing).
Create a template for your Controller (docs.silverstripe.org/en/developer_guides/templates/)
Community resources
silverstripe.org/slack Join other SilverStripe developers in the community Slack channel.
stackoverflow.com/questions/tagged/silverstripe Ask SilverStripe questions on Stack Overflow.
docs.silverstripe.org Searchable developer documentation, how-tos, tutorials, and reference.
api.silverstripe.org API documentation for PHP classes, methods and properties.
> **“Getting Started — To get started with the SilverStripe framework…”**
— is **Silverstripe’s default fallback template**. It usually means:
—
### ❌ Your page is working at the controller level, but…
– Silverstripe **can’t find a matching template** for the page type you created (e.g., `CustomPage.ss`).
—
### ✅ Fix: Create the correct template
Based on your class:
namespace App;
class CustomPage extends SiteTree
Your template should be at:
themes/your-theme/templates/App/CustomPage.ss
📌 Replace `your-theme` with the name defined in:
app/_config/theme.yml
Example:
---
Name: mytheme
---
SilverStripeViewThemeResolver:
default_theme: 'mytheme'
—
### ✅ Template content example (`CustomPage.ss`):
<% include Layout/Header %>
<h1>$Title</h1>
<p>This is my custom page template</p>
<% include Layout/Footer %>
—
### ✅ Then: Flush the cache
Visit:
/dev/build?flush
Or run in terminal:
vendor/bin/sake dev/build flush=all
—
After that, go back to your custom page URL:
/my-custom-page
Now it should render **your actual template**, not the fallback screen.
Let me know if you'd like to organize templates differently or support multiple themes.
In Silverstripe, **template folder structure must match the PHP namespace of your Page class**. Since your `CustomPage` is in the `App` namespace:
namespace App;
class CustomPage extends SiteTree
Silverstripe looks for the template here:
themes/your-theme/templates/App/CustomPage.ss
—
### ✅ Fix: Create missing folders and template file
Create this folder structure:
themes/your-theme/templates/App/
Then inside that, create:
CustomPage.ss
📄 Example file contents:
<% include Layout/Header %>
<h1>$Title</h1>
<p>This is a Custom Page.</p>
<% include Layout/Footer %>
—
### 🔄 Final step: Flush cache
Visit in browser:
/dev/build?flush
Or terminal:
vendor/bin/sake dev/build flush=all
—
Now visit the URL of your published Custom Page (e.g., `/my-custom-page`) — and you should see your custom template rendered.
Let me know if your namespace or theme name is different, and I’ll adjust the paths accordingly.
—
## ✅ Full Checklist to Resolve It:
—
### 1. ✅ **Check PHP Class Namespace and Name**
In `app/src/CustomPage.php`:
<?php
namespace App;
use SilverStripeCMSModelSiteTree;
class CustomPage extends SiteTree
{
private static $table_name = 'CustomPage';
}
—
### 2. ✅ **Check Template File Path**
The template for `AppCustomPage` **must** be:
themes/your-theme/templates/App/CustomPage.ss
🔧 To verify theme name, check:
app/_config/theme.yml
SilverStripeViewThemeResolver:
default_theme: 'your-theme' <--- make sure this matches folder name in themes/
So full path should be:
themes/your-theme/templates/App/CustomPage.ss
—
### 3. ✅ **Template File Content**
Make sure `CustomPage.ss` has **some visible content**, e.g.:
<% include Layout/Header %>
<h1>This is my custom page template</h1>
<p>Title from DB: $Title</p>
<% include Layout/Footer %>
—
### 4. ✅ **Create the Page in CMS**
– Go to `/admin`
– Add new page → Select `Custom Page`
– Give a title like **"Test Page"**
– Publish
📝 Note the URL segment (e.g. `test-page`)
—
### 5. ✅ **Rebuild & Flush Cache**
In browser:
/dev/build?flush
Or CLI:
vendor/bin/sake dev/build flush=all
—
### 6. ✅ **Visit the Page**
Go to:
https://your-site.local/test-page
You should now see your actual `CustomPage.ss` template content.
—
## 🧪 Still Seeing the Default?
If it still shows the “Getting Started” message, check:
– ❌ `CustomPage` is not a standalone `Controller` — make sure it **extends `SiteTree`**, not `Controller`
– ❌ There is no `CustomPage.ss` in `themes/your-theme/templates/Layout/` by mistake
– ❌ File not saved as `CustomPage.ss.txt` (check extensions on Windows)
—
If you're stuck, send me:
– The `namespace` and `class name` of your `CustomPage.php`
– The **exact full path** to your `CustomPage.ss` file
– Your theme name (from `theme.yml`)
– The page URL you’re visiting
I'll pinpoint the issue precisely.
—
## 🛠 Let's Debug Step-by-Step
Please go through each step **exactly as shown** below.
—
### ✅ Step 1: Confirm `CustomPage.php` and `CustomPageController.php`
File: `app/src/CustomPage.php`
<?php
namespace App;
use SilverStripeCMSModelSiteTree;
class CustomPage extends SiteTree
{
private static $table_name = 'CustomPage';
}
File: `app/src/CustomPageController.php`
<?php
namespace App;
use PageController;
class CustomPageController extends PageController
{
}
—
### ✅ Step 2: Confirm Template Path and Name
Assuming your theme is named **`mytheme`**, the correct template file must be:
themes/mytheme/templates/App/CustomPage.ss
🔁 Folder structure:
themes/
└── mytheme/
└── templates/
└── App/
└── CustomPage.ss
📄 Template content (very simple for testing):
<h1>IT WORKS</h1>
<p>This is the CustomPage template</p>
—
### ✅ Step 3: Check Active Theme
File: `app/_config/theme.yml`
SilverStripeViewThemeResolver:
default_theme: 'mytheme' # this must match your theme folder name
Then check this folder exists:
`themes/mytheme/`
If the folder is named something else (like `simple`), update the theme name in `theme.yml`.
—
### ✅ Step 4: Create Custom Page in CMS
– Go to `/admin`
– Add a new page → **Custom Page**
– Set **Title**: `Test Page`
– Set **URL Segment**: `test-page`
– Click **Publish**
—
### ✅ Step 5: Dev Build and Flush
Run in browser:
/dev/build?flush
Or via terminal:
vendor/bin/sake dev/build flush=all
—
### ✅ Step 6: Visit Page
Now go to:
http://localhost/test-page
You **must** see:
IT WORKS
This is the CustomPage template
—
## 🔍 Still Not Working?
If not, **please answer these 4 questions**:
1. What is the exact **namespace** in `CustomPage.php`?
2. What is the **full path** of your `CustomPage.ss` file (copy-paste)?
3. What is the **theme folder name** you’re using?
4. What **URL** are you visiting?
Once I have this info, I will tell you the exact cause.