Template file location/loading

<%- if @topic_view.topic.tags.present? %>
<%= t 'js.tagging.tags' %>: <%- @topic_view.topic.tags.each do |t| %> <%= t %> <%- end %>
<% end %>

Silverstripe Version:
4.5

Question:

I’m a front-end developer and haven’t used SS since version 2. I’m getting up to speed on how to create page types and a theme in SS4.

Following the tutorial about the holder/page pattern, I created a page type (and a holder) for “lessons”. I initially assumed the templates LessonHolder.ss and LessonPage.ss would go in my theme, but that didn’t work. I ended up finding the tutorial’s GitHub repo which had the templates in the app folder.

The only way my code for page types differs from the tutorial is that instead of “article” I have used “lesson”. When I load a lesson page I just get a plain page with the text on it.

What am I doing wrong? Is there a step I’ve missed? Are my templates in the wrong place?

Thank you for your time :slight_smile:

Hi,

The templates can go in your theme, but you’ll need to have the theme specified in the list in theme.yml in the config directory.

Another thing to be aware of is the use of PHP namespaces in CMS 4. If your page classes are in a namespace (as is the preferred option) then you need to reflect the namespaces in the templates directory structure.

I know it’s a bit of an abstract answer, but if you can give a bit more info about the above, we’ll be happy to help.

Thank you for the quick reply! :slight_smile:

The theme is specified in theme.yml and is working on standard Pages.

I have custom page types LessonHolder and LessonPage. These are showing and useable within the CMS.

From following the tutorial, the namespace is namespace SilverStripe\Lessons;.

I’ve tried adding the templates LessonHolder.ss and LessonPage.ss to themes/mytheme/templates/SilverStripe/Lessons but no avail. Also tried within a Layout subfolder, and in the Layout subfolder of mytheme/templates. Did a ?flush=all after each attempt, still just getting plain text when I try to view one of these pages.