Kirby\Patterns\Pattern::children PHP Method

children() public method

public children ( )
    public function children()
    {
        $children = new Collection();
        foreach (dir::read($this->root) as $dir) {
            if (!is_dir($this->root . DS . $dir)) {
                continue;
            }
            $pattern = new Pattern($this->path . '/' . $dir);
            $children->append($pattern->path(), $pattern);
        }
        return $children;
    }

Usage Example

Beispiel #1
0
 public function menu($patterns = null, $path = '')
 {
     if (is_null($patterns)) {
         $pattern = new Pattern();
         $patterns = $pattern->children();
     }
     if (!$patterns->count()) {
         return null;
     }
     $html = ['<ul class="nav">'];
     foreach ($patterns as $pattern) {
         if ($pattern->isHidden()) {
             continue;
         }
         $html[] = '<li>';
         $html[] = html::a($pattern->url(), '<span>' . $pattern->title() . '</span>', ['class' => $path == $pattern->path() ? 'active' : null]);
         if ($pattern->isOpen($path)) {
             $html[] = $this->menu($pattern->children(), $path);
         }
         $html[] = '</li>';
     }
     $html[] = '</ul>';
     return implode(array_filter($html));
 }