Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Template for code in sub directory


Go to End


2 Posts   1451 Views

Avatar
nedmas

Community Member, 2 Posts

8 September 2011 at 4:32am

Hi,

I'm trying to organise my mysite/code folder by placing my code in sub directories, however when I do this SS defaults to using the Page.ss template.

For example I have the following file:
mysite/code/CaseStudies/ListPage.php

Which contains the class:
CaseStudies_ListPage

And I've tried putting the template in the following:
theme/ListPage.ss
theme/CaseStudies_ListPage.ss
theme/CaseStudiesListPage.ss
theme/CaseStudies/ListPage.ss
theme/Layout/CaseStudies_ListPage.ss
theme/Layout/CaseStudiesListPage.ss
theme/Layout/CaseStudies/ListPage.ss

None of which work. Can this be done or am I attempting the imposible?

Avatar
Willr

Forum Moderator, 5523 Posts

9 September 2011 at 1:32pm

The location of a class and the template location are quite disjoint. Actually class paths in general in SS are usually redundant since the autoloader loads all of the classes for you.

What is likely causing the issue here is your class name. SS uses an _ in templates to denote an action - i.e ClassName_Action.ss. So when it comes time to pick your CaseStudies_ListPage it may think ListPage is the action, not part of the CaseStudies.

I suggest using CaseStudiesListPage as your class name since convention would state that, or you may be able to explicitly define a template file on your class

static $template = 'CaseStudies_ListPage';