Пример #1
0
 /**
  * Get the subnavigation html
  *   syntax: {$var|getsubnavigation[:type[:parentId[:startdepth[:enddepth[:excludeIds-splitted-by-dash[:tpl]]]]]}
  *
  *   NOTE: When supplying more than 1 ID to exclude, the single quotes around the dash-separated list are mandatory.
  *
  * @param string $var        The variable.
  * @param string $type       The type of navigation, possible values are: page, footer.
  * @param int    $pageId     The parent wherefore the navigation should be build.
  * @param int    $startDepth The depth to start from.
  * @param int    $endDepth   The maximum depth that has to be build.
  * @param string $excludeIds Which pageIds should be excluded (split them by -).
  * @param string $tpl        The template that will be used.
  * @return string
  */
 public static function getSubNavigation($var = null, $type = 'page', $pageId = 0, $startDepth = 1, $endDepth = null, $excludeIds = null, $tpl = '/Core/Layout/Templates/Navigation.tpl')
 {
     // build excludeIds
     if ($excludeIds !== null) {
         $excludeIds = (array) explode('-', $excludeIds);
     }
     // get info about the given page
     $pageInfo = Navigation::getPageInfo($pageId);
     // validate page info
     if ($pageInfo === false) {
         return '';
     }
     // split URL into chunks
     $chunks = (array) explode('/', $pageInfo['full_url']);
     // remove language chunk
     $hasMultiLanguages = FrontendModel::getContainer()->getParameter('site.multilanguage');
     $chunks = $hasMultiLanguages ? (array) array_slice($chunks, 2) : (array) array_slice($chunks, 1);
     if (count($chunks) == 0) {
         $chunks[0] = '';
     }
     // init var
     $parentURL = '';
     // build url
     for ($i = 0; $i < $startDepth - 1; $i++) {
         $parentURL .= $chunks[$i] . '/';
     }
     // get parent ID
     $parentID = Navigation::getPageId($parentURL);
     try {
         // get HTML
         $return = (string) Navigation::getNavigationHtml($type, $parentID, $endDepth, $excludeIds, (string) $tpl);
     } catch (Exception $e) {
         return '';
     }
     // return the var
     if ($return != '') {
         return $return;
     }
     // fallback
     return $var;
 }