Jump to:

3447 Posts in 1032 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » Template for code in sub directory

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

Page: 1
Go to End
Author Topic: 619 Views
  • nedmas
    Avatar
    Community Member
    2 Posts

    Template for code in sub directory Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: Template for code in sub directory Link to this post

    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';

    619 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.