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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

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

How to get the current page ID dynamically?

Go to End

4 Posts   8600 Views


Community Member, 131 Posts

20 March 2009 at 4:32am


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->setFilterFunction(create_function('$item','return $item->ClassName == "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

Community Member, 181 Posts

21 March 2009 at 2:13am

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


Hope that helps,


Community Member, 131 Posts

21 March 2009 at 12:23pm

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.


Community Member, 99 Posts

23 November 2010 at 12:29am

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;


control MyAdverts