How to get ID of current page in TYPO3 backend
Asked Answered
C

3

11

I'm using TYPO3 v8, how can I get the id of the current page that I'm editing in the backend?

Crooks answered 4/1, 2018 at 20:55 Comment(1)
In what context?Pulitzer
I
14

You can get current PageId like this.

in Controller file.

$currentPid = $GLOBALS['TSFE']->id

Using Typoscript.

temp.page_uid = TEXT
temp.page_uid.field = uid
Irena answered 5/1, 2018 at 4:1 Comment(2)
I tried this "$currentPid = $GLOBALS['TSFE']->id" and it didn't work ! I like to get the id of the current page in backoffice inside an extension that I have created and I don't have any controllersMender
The question specifically asked "in the backend". $GLOBALS['TSFE'] is instantiated in the frondend.Pulitzer
H
7

Example: In your controller:

$id = (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id');
Humid answered 5/11, 2018 at 16:11 Comment(1)
Just a hint: _GP('id') is only set when you have chosen a page in the page tree. Therefore, be aware of empty values - or zero when cast to integer as above.Veracity
H
2

This depends on context, examples:

  • If you are extending FormEngine (editing records), the parent page record is in the data array, prepared by some rather early data provider.
  • If you are adding a feature to the 'info' module, the page id is a GET parameter, you should be able to access this in your controller.
Howells answered 4/1, 2018 at 21:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.