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.

Showcase Questions /

Feedback and questions about sites in the Community Showcase.

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

Custom pagetype template issue


Go to End


3 Posts   3135 Views

Avatar
silverstripe_user

Community Member, 1 Post

8 December 2013 at 3:28am

Hello to all :) I just started using SilverStripe. I followed this tutorial http://www.silverstriperesources.com/articles/silverstripe-3-many-many-a-comprehensive-example/, everything is working fine except for the template part.

I created the ProductCategoryPage.ss file in the layouts folder and added the given code but its not getting displayed in the site(I did dev/build?flush=all),the template code is working when I add it to the layouts/page.ss so I think the ProductCategoryPage.ss is not getting included. Am I doing anything wrong?Can someone please help me out.

Avatar
martimiz

Forum Moderator, 1391 Posts

9 December 2013 at 2:11am

Note that that isn't an official SilverStripe tutorial despite the logo. This tutorial doesn't support version 3.1, and the template should really use <% loop %> in stead of <% control %>. The official SilverStripe tutorials are here: http://doc.silverstripe.org/framework/en/ (look at 5 for relation management)

After changing templates, you should just ?flush=1, never mind the dev/build, that is for updating the DataBase and in the newest versions of SilverStripe doesn't seem to flush the template cache anymore (if I'm correct, not toally shure about that)

Beside that: hard to tell what goes wrong, based on your information alone... Check for version and typo's/omissions in code and filenames I'd suggest :)

Martine

Avatar
Mia

Community Member, 8 Posts

6 September 2014 at 2:14am

Hi,

Every template needs a corresponding *.php file.

i.e. You want to create a page that shows Products

class PageProduct extends Page{
}

class PageProduct_Controller extends Page_Controller{

}

Then you need to create a corresponding template file called PageProduct.ss.

Same thing with inheritance. You can create children for a page by creating a function, adding it to the allowed actions and creating a *.ss file with the name PageProduct_functionName.ss. As soon as you redirect to that function it will call that child page.

Furthermore, you should only flush=all to clear cached images. Any time you add, or include a template, and only then, do you have to flush ON THAT PAGE (important) by doing /url/products?flush or /url/viewProduct?flush (the 1 is no longer required).

One more thing to note, it is very important that you put all the template (.ss) files in the layout folder. The way Silverstripe is built, it always loads the Page.ss from themes, and where the $Layout is called in that page, it will look for a corresponding *.ss file in the layout folder. So if PageProduct was loaded, it will load Page.ss and include PageProduct.ss in the $Layout variable.

Hope that helps!