Layout template location for custom module

I have a running website on SilverStripe 4.6 with all my code in the app/src folder. I thought it would be cleaner to move my code into seperate newly created modules. I’ve been successful mostly except with the templating part.

Suppose I have vendor/myvendor/blogmodule/src/BlogPageController.php with namespace MyVendor\BlogModule\

Where should I put my BlogPage.ss template? I want it to be rendered with Page.ss from my theme folder and Layout/BlogPage.ss as the $Layout.

I’ve tried many locations like

vendor/myvendor/blogmodule/templates/layout/BlogPage.ss
themes/mytheme/templates/MyVendor/BlogModule/Layout/
… and more

Your template would be:

vendor/myvendor/blogmodule/templates/MyVendor/BlogModule/Layout/BlogPage.ss

Once you’re in the templates directory, your structure needs to match the namespace of the classes.
This allows for templates to be overridden / cascaded in other places such as site themes.

My template is now in themes/mytheme/templates/MyVendor/BlogModule/Layout/BlogPage.ss and works perfectly.

I simply move it to vendor/myvendor/blogmodule/templates/MyVendor/BlogModule/Layout/BlogPage.ss I do ?flush and … poof, it’s gone. Just Page.ss renders without BlogModule inside it.

Very confused. Maybe something to do with theme.yml in my app folder?
---
Name: mytheme
---
SilverStripe\View\SSViewer:
themes:
- '$public'
- '<mytheme>'
- '$default'

@Faloude Did you find the solution? I have the exact same issue and apply Dev/Build/?flush=all and the template doesn’t appear.

I ended up placing the templates files in vendor/myvendor/module-name/templates/ and I guess it has been taken as being part of the $default theme

I ended up just moving it to the themes folder which I’m actually not that happy with but it works. I’ve found templating in SS not so fun all the way back from 3.x.

1 Like