This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

milanblasko2844565
milanblasko2844565

Hi, Please I need help. I have a static page which has children pages and grandchildren page

  • Top level page -- Children page --- Grandchildren page How I get slug and title of Top level page If I'm on Children page or Grandchildren page Thanks for information.

Last updated

mjauvin
mjauvin

The classes/PageList class has a getPageParent() method

mjauvin
mjauvin

Actually, the Page class has a getParent() method which uses the above method...

milanblasko2844565
milanblasko2844565

Hi, Thank for reply. But It still doesn't work as it should. If I on url /samosprava/mestsky-urad return value "samosprava" but if url is /samosprava/mestsky-urad/vedenie-mesta than return value "samosprava-mestsky-urad". I want it to always show toplevel page ("samosprava") My php code in phpblock in layout:

$theme = Cms\Classes\Theme::getEditTheme();
    $pageList = new RainLab\Pages\Classes\PageList($theme);
    $page = $this->page['apiBag']['staticPage'];
    $allPages = $pageList->listPages();
    $pageParent = $pageList->getPageParent($page);

Last updated

mjauvin
mjauvin

You need to check if the parent page has a parent... if not, then you know you have the top-level page.

milanblasko2844565
milanblasko2844565

Hi. Sorry but I'm not a beckend developer. I need only always top-level page. If I on /samosprava/mestsky-urad/vedenie-mesta than I need get "samosprava" from variable.

1-6 of 6

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.