Skip to content

Commit

Permalink
Added support for collections with @root page and recurse flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Oct 19, 2015
1 parent db2caf4 commit 077ba28
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions system/src/Grav/Common/Page/Page.php
Expand Up @@ -1962,6 +1962,10 @@ protected function evaluate($value)
if (!empty($parts)) {
switch ($parts[0]) {
case 'modular':
if (!empty($params) && $params[0] === false) {
$results = $this->children()->nonModular()->published();
break;
}
$results = $this->children()->modular()->published();
break;
case 'children':
Expand All @@ -1973,10 +1977,24 @@ protected function evaluate($value)

case '@page':
if (!empty($params)) {
$page = $this->find($params[0]);
if ($page) {
$results = $page->children()->nonModular()->published();
/** @var Pages $pages */
$pages = self::getGrav()['pages'];

list($what, $recurse) = array_pad($params, 2, null);

if ($what == '@root') {
$page = $pages->root();
} else {
$page = $this->find($what);
}

if ($page) {
if ($recurse) {
$results = $pages->all($page)->nonModular()->published();
} else {
$results = $page->children()->nonModular()->published();
}
}
}
break;

Expand Down

2 comments on commit 077ba28

@hwmaier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the recursion is a very useful feature, thanks for adding it. But I would have expected it to be in a form similar to the present dot-syntax. Something more like below, I also added some options for future additions like siblings etc.

content:
  items:
    - @page: /fruit
    - @page.descendants: /fruit  # recurse, alternative syntax to recurse flag...
    - @root   # Alternative syntax to using  @page: @root
    - @root.descendants  # Same as above but recurse
    - @self.parent    # Just the parent page
    - @self.siblings   # A collection of all other pages on this level
    - @self.modular
    - @self.children
    - @self.descendants # recurse
    - /fruit/pear     # Add just a single named page to the collection
    - /fruit/apple    # Add just a single named page to the collection

@rhukster
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are some good ideas. Please create an issue for this so it is not lost in the noise. Thanks!

Please sign in to comment.