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.

Archive /

Our old forums are still available as a read-only archive.

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

adding a page type, a couple of questions....


Go to End


11 Posts   3210 Views

Avatar
Nicolaas

Forum Moderator, 224 Posts

7 September 2007 at 2:29pm

Edited: 07/09/2007 2:33pm

Hi,

I successfully added some page types, like this:

class consultingPage extends Page {
static $db = array();
static $has_one = array();
public function pageCodeForCss() {
return 'consulting';
}
}

class consultingPage_Controller extends Page_Controller {

}

I have updated the database, and consultingPage is now a page type. Here are some questions I have:

1. What is the proper way to delete the pagetype again?

2. How can I access the extra variable I would like to add to the pageType from within the .ss templates?

3. within the CMS, how can I change the add pagetype list? I want certain templates only to be available in certain parts of the sites, plus, I dont really want the newsletter option to be available, etc...

Thanks

Nicolaas

Avatar
Willr

Forum Moderator, 5523 Posts

7 September 2007 at 6:32pm

Edited: 07/09/2007 6:35pm

1. What is the proper way to delete the pagetype again?

Delete the pagetype.php file, rebuild the database is probably the easiest way to go about deleting it!!

2. How can I access the extra variable I would like to add to the pageType from within the .ss templates?

if you make a function like this on your page controller

[code php]
function pageCodeForCSS() {
//
return $code;
}

you should be able to access $code in the SS template like $pageCodeForCSS OR you can have <% control pageCodeForCSS %>$Code<% end_control %>

3. within the CMS, how can I change the add pagetype list?

I dont believe you can edit this list currently and hide/show options just yet sadly, this may be something we have in the future eg Only showing BlogEntrys on BlogHolders... I dont think it goes that far at the moment

Avatar
Sean

Forum Moderator, 922 Posts

7 September 2007 at 6:45pm

Edited: 07/09/2007 6:54pm

1. Make sure any pages using that class name are reset back to Page before deleting the php file and rebuilding the database. Otherwise, you'll get an error about 'templates not found' or 'couldn't find this class name'.

2. Accessing an extra variable? if you've added it to the static $db = array() then you can call it directly. eg. static $db = array('CoolThing' => 'Text');

You then just use $CoolThing in your template

3. There currently isn't any functionality supporting this, I don't believe. However, you could probably go about doing this starting with SiteTree.php.

Cheers,
Sean

Avatar
Nicolaas

Forum Moderator, 224 Posts

7 September 2007 at 6:45pm

Thanks a million!

Avatar
Nicolaas

Forum Moderator, 224 Posts

7 September 2007 at 7:10pm

Hi

I have just done this, but I get a bad error:

<b>Fatal error</b>: Class 'about' not found in <b>/home/winsboroughconz/www/sapphire/core/Object.php</b> on line <b>71</b><br >

I have not changed anything in the about class!

What did I do wrong?

Avatar
Sean

Forum Moderator, 922 Posts

7 September 2007 at 10:38pm

What did you do to achieve that problem? You could try adding ?flush=1 at the end to see if that helps...

Cheers,
Sean

Avatar
Nicolaas

Forum Moderator, 224 Posts

7 September 2007 at 11:42pm

Edited: 10/09/2007 3:02pm

..... quoted error here.....

Avatar
Sean

Forum Moderator, 922 Posts

8 September 2007 at 12:08am

Edited: 08/09/2007 12:10am

It's likely the home page had a ClassName field in the db set to a custom class name, and when you removed that class and rebuilt the database it would've set it to blank because it doesn't exist anymore. Because of that, it's attempting to compensate by using the class name of 'SiteTree' instead as a fall back measure.

Solution? Jump into phpMyAdmin, set the ClassName field for the home page back to 'Page'.

Cheers,
Sean

Go to Top