Jump to:

5552 Posts in 1742 Topics by 1226 members

Customising the CMS

SilverStripe Forums » Customising the CMS » How to get the current page ID dynamically?

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

Page: 1
Go to End
Author Topic: 5704 Views
  • theAlien
    Avatar
    Community Member
    131 Posts

    How to get the current page ID dynamically? Link to this post

    Hi,

    How do I extract the current page ID (to $id)?
    I would like to do something like this:

    $contactform = new TreeDropdownField("ContactformID","Contactform","SiteTree");
    $contactform->setTreeBaseID($id);
    $contactform->setFilterFunction(create_function('$item','return $item->ClassName == "ContactForm";'));
    $fields->addFieldToTab("Root.Content.Main",$contactform);

    This way I would like to retrieve all contactforms that are children of the current page.
    If I'm asking something that's impossible: please tell me. Otherwise: give me a clue ;-)

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: How to get the current page ID dynamically? Link to this post

    You should be able to get the current page's ID with:

    $this->ID;

    Hope that helps,
    Ben

  • theAlien
    Avatar
    Community Member
    131 Posts

    Re: How to get the current page ID dynamically? Link to this post

    Shame on me... that's just too easy... I should've thought about it myself :$
    I didn't, so thanks alot. It worked right away.

  • merrick_sd
    Avatar
    Community Member
    95 Posts

    Re: How to get the current page ID dynamically? Link to this post

    How do i get the current page id. it doesn seem t work when withing a function
    I just seem to get the ID of FlashAdvertChoice table

    function MyAdverts() {
    $adverts = DataObject::get_one("MainFlashAdvert");
    $CurrentPageID = $this->ID;
    return ($adverts) ? DataObject::get("FlashAdvertChoice", "PageID = $CurrentPageID ", "ID DESC", "") : false;
    }

    .ss

    control MyAdverts
    $CurrentPageID

    end_control

    5704 Views
Page: 1
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.