public function render()
 {
     if ($this->items) {
         if (!$this->baseURI) {
             throw new Exception("Call setBaseURI() before render()!");
         }
         if ($this->selectedFilter === false) {
             throw new Exception("Call selectFilter() before render()!");
         }
     }
     $view = new AphrontSideNavView();
     $view->setFlexNav($this->flexNav);
     $view->setFlexible($this->flexible);
     $view->setShowApplicationMenu($this->showApplicationMenu);
     $view->setActive($this->active);
     if ($this->user) {
         $view->setUser($this->user);
     }
     if ($this->currentApplication) {
         $view->setCurrentApplication($this->currentApplication);
     }
     foreach ($this->items as $item) {
         list($type, $key, $name) = $item;
         switch ($type) {
             case 'custom':
                 $view->addNavItem($name);
                 break;
             case 'spacer':
                 $view->addNavItem('<br />');
                 break;
             case 'label':
                 $view->addNavItem(phutil_render_tag('span', array(), phutil_escape_html($name)));
                 break;
             case 'filter':
                 $class = $key == $this->selectedFilter ? 'aphront-side-nav-selected' : null;
                 $class = trim($class . ' ' . idx($item, 'class', ''));
                 if (empty($item['uri'])) {
                     $href = clone $this->baseURI;
                     $href->setPath($href->getPath() . $key . '/');
                     $href = (string) $href;
                 } else {
                     if (empty($item['relative'])) {
                         $href = $item['uri'];
                     } else {
                         $href = clone $this->baseURI;
                         $href->setPath($href->getPath() . $item['uri']);
                         $href = (string) $href;
                     }
                 }
                 $view->addNavItem(phutil_render_tag('a', array('href' => $href, 'class' => $class), phutil_escape_html($name)));
                 break;
             default:
                 throw new Exception("Unknown item type '{$type}'.");
         }
     }
     $view->appendChild($this->renderChildren());
     return $view->render();
 }