Menu\Items\ItemList::render PHP Method

render() public method

Get the evaluated string content of the ItemList.
public render ( integer $depth ) : string
$depth integer The depth at which the ItemList should be rendered
return string
    public function render($depth = 0)
    {
        if (!is_int($depth)) {
            throw new Exception("The render method doesn't take any arguments anymore, you can now configure your menu via the config file.");
        }
        // Check for maximal depth
        $maxDepth = $this->getOption('max_depth');
        if ($maxDepth !== -1 and $depth > $maxDepth) {
            return false;
        }
        // Render contained items
        $contents = null;
        if (count($this->children) == 0) {
            return "";
        }
        foreach ($this->children as $item) {
            $contents .= $item->render($depth + 1);
        }
        $element = $this->getElement();
        if ($element) {
            $contents = Element::create($element, $contents, $this->attributes)->render();
        }
        return $contents;
    }

Usage Example

Ejemplo n.º 1
0
 public function testMenuCanSetGlobalOptions()
 {
     Menu::setOption('item.element', 'dl');
     $list = new ItemList();
     $list->add('#', 'foo');
     $this->assertHTML($this->matchListWithItem('ul', 'dl'), $list->render());
     $this->assertHTML($this->matchLink(), $list->render());
 }