Not recognising new Page Types

templates
silverstripe-4
Tags: #<Tag:0x00007f10c741f3c8> #<Tag:0x00007f10c741f288>

#1

Silverstripe Version: 4.3

Question:

I am following the tutorials for creating a new page type. I have followed the steps in https://www.silverstripe.org/learn/lessons/v4/working-with-multiple-templates-1 and I have done a dev/build, but it is not recognising that there is a new page type there.

Am I missing something?


#2

Can you please post the code for your new page type?


#3

HomePage.php

<?php

namespace SilverStripe\Lesson {

use Page;    

class HomePage extends Page 
{

}
}

HomePageController.php

<?php

namespace SilverStripe\Lesson {

use PageController;    

class HomePageController extends PageController 
{

}
}

#4

You’ve got an extra set of curly brackets in there, as far as I know that’s not valid and should just be:

<?php

namespace SilverStripe\Lesson;

use Page;    

class HomePage extends Page 
{

}

#6

I have tried both ways and it hasn’t worked either way! I don’t get an error it just doesn’t seem to find it!


#5

That syntax should be fine, you can specify namespaces with curly brackets.


#7

Could you clarify what you mean here? Is it that the page type doesn’t show up in the CMS?


#9

Maybe try:
extends \Page …


#8

Certainly. I have created the PHP files in the correct location and done the /dev/build?flush=all the training document states that I should get some blue text that says there has been a change to Site Tree, I don’t get that.

It also says that I should be able to edit my home page and change the type to my new Home Page type, but it’s not in the list.


#10

So this is weird. I tried your suggestion, no change. It made me think that the build wasn’t looking in there. So I put some out of context text in one of the files and tried again and it crashed. This was good because at least I knew it was looking in there.

I took the text out and reran dev/build. No change to the output, BUT, the new template is now in the page types. I quickly created another page type I needed and it worked properly!

It’s all very weird, but thank you all so much for your help!


#12

I commented just a few minutes ago on that point :slight_smile: The text output doesn’t happen every time, the lessons are a bit misleading in that respect.

Glad it’s working now!


#11

You’ll only tend to get this the first time there was a change. It may not be evident every time you run a dev/build

This is the actual issue. Once the page type has been added, you should see it in the ‘New Page’ dialogue or if you edit a page and choose the page type under ‘Settings’.