Jump to:

3443 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » Mysite will not use the .ss file I have created

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

Page: 1
Go to End
Author Topic: 534 Views
  • SaturnJ
    Avatar
    Community Member
    4 Posts

    Mysite will not use the .ss file I have created Link to this post

    I have a new page type defined as below;

    XYZ.php
    <?php
    class XYZ extends Page
    { blah blah blah}
    ?>

    And then I have template for the same page type under 'themes\simple\templates\Layout'. As you can see I am using the standard 'simple' theme.

    But for some reason, the site is loading the 'Page.ss' template instead of XYZ.ss. I have triple checked everything, what is going wrong. Any suggestions are welcome as this seems to be really simple but ......

  • ecristen
    Avatar
    Community Member
    2 Posts

    Re: Mysite will not use the .ss file I have created Link to this post

    Try implementing the Controller class also.

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Mysite will not use the .ss file I have created Link to this post

    also you have to flush after doing this. and yes @ecristen, you need to make the controller class too

    class XYZ_controller extends Page_controller
    { blah blah blah}

  • Shweta
    Avatar
    Community Member
    2 Posts

    Re: Mysite will not use the .ss file I have created Link to this post

    hi same Thing is happening with mysite. I am doing tutorial one for 2.4 version. I used all solutions provided before.

    As given in Tutorial. I created HomePage.php and then HomePage.ss but after I flush cache also it is using default ContentController.ss template for Home page.

    Can anyone tell me what's wrong?

  • spekulatius
    Avatar
    Community Member
    4 Posts

    Re: Mysite will not use the .ss file I have created Link to this post

    I got the same problem on 3.1.2.

  • spekulatius
    Avatar
    Community Member
    4 Posts

    Re: Mysite will not use the .ss file I have created Link to this post

    I found a fix for my problem.

    I copied my classes from the Page.php example. In Page.php the classes are defined as:

    class Page extends SiteTree

    So my copy was:

    class CategoryPage extends SiteTree

    With this the a default template was used instead of my customized template. After I changed it to:

    class CategoryPage extends Page

    it worked.

    Simular for the Controller class of course.

  • Shweta
    Avatar
    Community Member
    2 Posts

    Re: Mysite will not use the .ss file I have created Link to this post

    I already did that but no change.
    my code is :

    Page.php:

    <?php
    class Page extends SiteTree {

       public static $db = array(
       );

       public static $has_one = array(
       );

    }
    class Page_Controller extends ContentController {

       /**
        * An array of actions that can be accessed via a request. Each array element should be an action name, and the
        * permissions or conditions required to allow the user to access it.
        *
        * <code>
        * array (
        * 'action', // anyone can access this action
        * 'action' => true, // same as above
        * 'action' => 'ADMIN', // you must have ADMIN permissions to access this action
        * 'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
        * );
        * </code>
        *
        * @var array
        */
       public static $allowed_actions = array (
       );

       public function init() {
          parent::init();

          // Note: you should use SS template require tags inside your templates
          // instead of putting Requirements calls here. However these are
          // included so that our older themes still work
          Requirements::themedCSS('layout');
          Requirements::themedCSS('typography');
          Requirements::themedCSS('form');
       }
    }
    ?>
    ------------------------------------------------------------------------------------------------------------------------------------
    Page.ss:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" >
    <head>
    <% base_tag %>
    $MetaTags
    <% require themedCSS(layout) %>
    <% require themedCSS(typography) %>
    <% require themedCSS(form) %>
    </head>
    <body>
    <div id="Main">
    <ul id="Menu1">
    <% control Menu(1) %>
    <li class="$LinkingMode"><a href="$Link" title="Go to the &quot;{$Title}&quot; page">$MenuTitle</a></li>
    <% end_control %>
    </ul>
    <div id="Header">
    <h1>$Title</h1>
    </div>
    <div id="ContentContainer">
    $Layout
    </div>
    <div id="Footer">
    <span>Visit <a href="http://www.silverstripe.com" title="Visit www.silverstripe.com">www.silverstripe.com</a>; to download the CMS</span>
    </div>
    </div>
    $SilverStripeNavigator
    </body>
    </html>
    --------------------------------------------------------------------------------------------------------------------------------------------------------

    HomePage.php:
    <?php
    /**
    * Defines the HomePage page type
    */

    class HomePage extends Page {
    static $db = array(
    );
    static $has_one = array(
    );
    }

    class HomePage_Controller extends Page_Controller {

    }
    ?>
    ----------------------------------------------------------------------------------------------------------------------------------------
    Page.ss:(themes\tutorials\templates\Layouts\Page.ss)
    <% if Menu(2) %>
    <ul id="Menu2">
    <% control Menu(2) %>
    <li class="$LinkingMode"><a href="$Link" title="Go to the &quot;{$Title}&quot; page">$MenuTitle</a></li>
    <% end_control %>
    </ul>
    <% end_if %>

    <div id="Content" class="typography">
    <% if Level(2) %>
    <div class="breadcrumbs">
    $Breadcrumbs
    </div>
    <% end_if %>
    $Content
    $Form
    </div>

    ---------------------------------------------------------------------------------------------------------------------------
    HomePage.ss(themes\tutorials\templates\Layouts\HomePage.ss )

    <div id="Banner">
    <img src="themes/tutorial/images/welcome.png" alt="Homepage image" />
    </div>
    <div id="Content" class="typography">
    $Content
    </div>
    --------------------------------------------------------------------------------------------------------------------------------

    Everything is as mentioned in tutorial .. so what is going wrong????

    534 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.