Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » adding a page type, a couple of questions....

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

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

Page: 1 2
Go to End
Author Topic: 2407 Views
  • Nicolaas
    Avatar
    Forum Moderator
    213 Posts

    adding a page type, a couple of questions.... Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: adding a page type, a couple of questions.... Link to this post

    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

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: adding a page type, a couple of questions.... Link to this post

    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

  • Nicolaas
    Avatar
    Forum Moderator
    213 Posts

    Re: adding a page type, a couple of questions.... Link to this post

    Thanks a million!

  • Nicolaas
    Avatar
    Forum Moderator
    213 Posts

    Re: adding a page type, a couple of questions.... Link to this post

    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?

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: adding a page type, a couple of questions.... Link to this post

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

    Cheers,
    Sean

  • Nicolaas
    Avatar
    Forum Moderator
    213 Posts

    Re: adding a page type, a couple of questions.... Link to this post

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

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: adding a page type, a couple of questions.... Link to this post

    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

    2407 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.