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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

[solved] Question about custom page type setup


Go to End


10 Posts   3981 Views

Avatar
Faloude

Community Member, 55 Posts

4 March 2015 at 2:22pm

I've succesfully implemented my own theme into SilverStripe and I am trying to find out how $Layout works.

Suppose I have Page.ss in my template folder with the following

<html>
<body>
$Layout
</body>

A Page.ss as follows template_name/Templates/Layout/Page.ss

I am any other page than the homepage!

A HomePage.ss as follows: template_name/Templates/Layout/HomePage.ss

I am the homepage!

I assumed that when you have a file named "HomePage.ss" in the Layout folder, this will always be the rendered page (on the spot of $Layout in the main Page.ss) when visiting the homepage of the site. But when opening my site, the Layout/Page.ss is always rendered. Was my assumption incorrect?

Avatar
Rhym

Community Member, 12 Posts

4 March 2015 at 2:33pm

Have you done a ?flush=all ?

Avatar
Faloude

Community Member, 55 Posts

4 March 2015 at 2:36pm

I've tried that already, no change. Thanks for the suggestion though

Avatar
Rhym

Community Member, 12 Posts

4 March 2015 at 2:37pm

Is your home page set to the page type of HomePage?

Avatar
Faloude

Community Member, 55 Posts

4 March 2015 at 2:41pm

No it is not! The only choices I have in the settings page are:

  • Virtual page
  • Error page
  • Page
  • Redirector page

Avatar
Webdoc

Community Member, 349 Posts

5 March 2015 at 12:46am

Edited: 05/03/2015 12:49am

1. Add this code to mysite/code folder to file named 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 {
 
}
?>

2. After this use - http://yoursite.com/dev/build?flush=1
3. change the pagetype to homepage and save publish
4. http://yoursite.com/?flush=all to renew the design code.

--------------------------------------------------------------------------------------------------------------------------------
Arvixe Web Hosting / SilverStripe Community Liaison | Looking for quality SilverStripe Web Hosting? Look no further than Arvixe Web Hosting!

Avatar
Faloude

Community Member, 55 Posts

5 March 2015 at 1:38am

Edited: 05/03/2015 2:00am

I changed HomePage.ss to HomePage.php and performed all steps. Unfortunately the page type "Home" still isn't available.

edit: I'm using SilverStripe 3.1

edit 2: I've just watched the video related to this issue (setting up custom page type) and it seems that the person in the video is has his website folder in the silverstripe root folder whereas I have it placed in the theme folder (themes/my_own_theme/templates/layouts/HomePage.ss). Is this why I can't set up a new pagetype?

The video: http://www.silverstripe.org/learn/lessons/lesson-4-working-with-multiple-templates

Avatar
Nightjar

Community Member, 28 Posts

5 March 2015 at 2:00am

Edited: 05/03/2015 2:02am

I think here Tutorial #1 will help you understand much more.
http://doc.silverstripe.org/en/tutorials/building_a_basic_site/#using-a-different-template-for-the-home-page
(There's a deprecation warning at the top of the page, but ignore that. It's still very relevant.)

Basically page types are defined in PHP.
Pages use templates to render, based on their classname.
Your initial assumption is correct, however the page type must match the template type.

Basically there are 3 files at play here.
mysite/code/Homepage.php - class HomePage extends Page (along with a matching controller)
themes/yourtheme/templates/Page.ss - header, $Layout, footer)
themes/yourtheme/templates/Layout/HomePage.ss - Used as contents of $Layout - filename must match classname(.ss)

Go to Top