How to tell renderwith where to find template when in CMS-environment?

SS4

I wrote a backend module that uses template files to generte PDFs. Sadly the renderWith function can only find my pdfTemplate.ss if it is in vendor/silverstripe/cms/templates/mynamespace/mytemplate

Which means it would be overwritten on the next update…

So how to configure renderwith to look for template in root/themes/mytheme/templates ?

thank in advance
fabian

Hi Fabian,

The ThemeResourceLocator takes a second parameter to supply a theme list.

The issue you are having is not new to SS4 - Silverstripe CMS has always explicitly unset the theme (so “front-end” themes don’t interfere with the CMS layout).

One way to re-set this behaviour without changing global state (setting the theme list) in SS4 is:

ThemeResourceLoader::inst()->findTemplate(
    $yourTemplate,
    SSViewer::config()->uninherited('themes')
);

The second parameter in this example is the default behaviour of SSViewer::get_themes

Another way to handle this is to enable the themes again via the SSViewer.theme_enabled configuration variable (the CMS disables the themes IIRC). But again this is modifying global state, which you must remember to reset after processing.