https://github.com/silverstripeltd/product-issues/issues/875 (private repo) outlines a POC for abstracting the template layer into its own module. This issue is about taking that POC and implementing it properly for CMS 6.
This will provide the following benefits:
- improved separation between the view and model layers
- improved architecture for the view layer
- opens the door to further decouple the CMS from the template layer over time (e.g. could move all templates out into an optional 'admin-theme', and allow projects to introduce their own full 'admin-theme' similar to how the Drupal backend works)
- ability to swap out the rendering engine easily in the future, or per project, if that's desired
Related issues
Check if these can be sensibly resolved as part of this work
Notes
- Check everywhere that uses
ThemeResourceLoader::findTemplate() and SSViewer::get_templates_by_class() if those end up being moved or significantly refactored
- Don't forget to check what's going on with
ViewableData_Customised and ViewableData_Debugger - at a minimum they need the same renaming treatment that ViewableData is getting.
ContentNegotiator has some weird regex related to the output of <% base_tag %>
Acceptance criteria
Explicitly excluded
Strong-typing PRs
Adding some strong typing to some existing API before I start the refactor so I have more confidence in the types of the values I'm dealing with and passing through to the template layer.
Kitchen sink CI run
Renaming PRs
CMS 5
CMS 6
kitchen sink CI
The CI failure is unrelated to these PRs and was caused by a fluent PR being merged before the code it relies on.
Refactor PRs
CMS 5
CMS 6
Kitchen sink CI run: https://github.com/creative-commoners/recipe-kitchen-sink/actions/runs/11584927001
I've made an example of what a twig module may look like, including twig versions of the simple theme templates.
https://github.com/GuySartorelli/silverstripe-twig
The readme notes some ways template creators will need to workaround the way the abstraction works - notably having to use getRawDataValue() for conditional checks.
If you want to try it out to test the abstraction, follow the instructions in the readme to set it as the renderer for PageController
Migration PRs
CMS 5
CMS 6
Kitchen sink CI
The above PRs should be merged before any others, since CI won't be happy on the others until the new repo is in packagist, and it can't be added to packagist until composer.json is added.
Supported modules PR is needed for GHA to generate a matrix so we can actually test the module itself.
https://github.com/silverstripeltd/product-issues/issues/875 (private repo) outlines a POC for abstracting the template layer into its own module. This issue is about taking that POC and implementing it properly for CMS 6.
This will provide the following benefits:
Related issues
Check if these can be sensibly resolved as part of this work
$scope->locally())ViewableData#11262ViewableData::Me()out ofViewableDataand into the template layer #11261Notes
ThemeResourceLoader::findTemplate()andSSViewer::get_templates_by_class()if those end up being moved or significantly refactoredViewableData_CustomisedandViewableData_Debugger- at a minimum they need the same renaming treatment thatViewableDatais getting.ContentNegotiatorhas some weird regex related to the output of<% base_tag %>Acceptance criteria
.sstemplates is moved into a new repository calledsilverstripe/silverstripe-template-renderersilverstripe/frameworksince that contains.sstemplates.SSViewerremains in framework, and has the following responsibilities:process()on theSSViewerinstance, which instantiates a template renderer and asks for the rendered HTML)RequirementsAPI into the rendered HTML resultDBHtmlTextSSVieweror both moved to the new moduleSSViewerto abstractly interact with a template rendering engine.ssextensionViewLayerDataclass is created.DBFieldinstance (plus arrays to eitherArrayListorArrayData)ModelData::exists()where that has been implemented)ViewableDatais renamed toModelData, since it really represents a "Model" in the MVC sense.Explicitly excluded
ViewableDataper https://github.com/silverstripeltd/product-issues/issues/875#issuecomment-2249358959 (can easily do as a follow-on card afterward)Strong-typing PRs
Adding some strong typing to some existing API before I start the refactor so I have more confidence in the types of the values I'm dealing with and passing through to the template layer.
Kitchen sink CI run
Renaming PRs
CMS 5
CMS 6
kitchen sink CI
The CI failure is unrelated to these PRs and was caused by a fluent PR being merged before the code it relies on.
Refactor PRs
CMS 5
CMS 6
Kitchen sink CI run: https://github.com/creative-commoners/recipe-kitchen-sink/actions/runs/11584927001
I've made an example of what a twig module may look like, including twig versions of the simple theme templates.
https://github.com/GuySartorelli/silverstripe-twig
The readme notes some ways template creators will need to workaround the way the abstraction works - notably having to use
getRawDataValue()for conditional checks.If you want to try it out to test the abstraction, follow the instructions in the readme to set it as the renderer for
PageControllerMigration PRs
CMS 5
CMS 6
Kitchen sink CI
The above PRs should be merged before any others, since CI won't be happy on the others until the new repo is in packagist, and it can't be added to packagist until composer.json is added.
Supported modules PR is needed for GHA to generate a matrix so we can actually test the module itself.