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

Mysite will not use the .ss file I have created


Go to End


7 Posts   4310 Views

Avatar
SaturnJ

Community Member, 4 Posts

23 November 2013 at 12:36pm

Edited: 24/11/2013 1:50am

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

Avatar
ecristen

Community Member, 2 Posts

4 December 2013 at 6:27am

Try implementing the Controller class also.

Avatar
Nivanka

Community Member, 400 Posts

5 December 2013 at 5:33am

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}

Avatar
Shweta

Community Member, 2 Posts

19 January 2014 at 9:20pm

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?

Avatar
spekulatius

Community Member, 5 Posts

20 January 2014 at 12:19am

I got the same problem on 3.1.2.

Avatar
spekulatius

Community Member, 5 Posts

20 January 2014 at 12:34am

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.

Avatar
Shweta

Community Member, 2 Posts

20 January 2014 at 1:12am

Edited: 20/01/2014 3:16am

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" xml: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????