public function pageContent(Page $page)
 {
     $content = $page->getContent();
     if (!$content) {
         return '';
     }
     if ($page->hasFeature('layout')) {
         if (!is_array($content)) {
             throw new \InvalidArgumentException(sprintf('Page with id "%s" has a layout but no array content', $page->getId()));
         }
         $layoutFeature = $page->getFeature('layout');
         $layout = $layoutFeature->getContent();
         $search = array();
         $replace = array();
         foreach ($content as $key => $value) {
             $search[] = '{{' . $key . '}}';
             $replace[] = $value;
         }
         $content = preg_replace_callback('/[{]{2}([^}]*)[}]{2}/i', function ($key) use($content) {
             return isset($content[$key[1]]) ? $content[$key[1]] : '<!-- NO-CONTENT -->';
         }, $layout);
     }
     if (is_array($content)) {
         $content = implode('', $content);
     }
     return $content;
 }
 private function buildMenu(ItemInterface $rootMenu, Page $page, array $options)
 {
     $titleGetter = 'get' . ucfirst($options['title_property']);
     $menu = $rootMenu->addChild($page->{$titleGetter}())->setAttribute('id', $page->getId());
     if ($options['root_as_child']) {
         $menu->addChild($page->{$titleGetter}())->setUri($page->getMainUrl())->setAttribute('id', $page->getId());
     }
     foreach ($page->getChildren() as $childPage) {
         $menu->addChild($childPage->{$titleGetter}())->setUri($childPage->getMainUrl())->setAttribute('id', $childPage->getId());
     }
 }