cms
cms copied to clipboard
Children tag pair doesn't return as expected
Bug description
To output and loop through child page(s) data when on a parent page.
Have tried to template in a number of ways but nothing . I've seen {{ children }}
referenced in the Nav docs but I've not found {{ children }}
mentioned explicitly in the way the {{ parent }}
tag is.
Using {{ dump }}
I see:
? Related to #5554 ? Related to #5565
How to reproduce
- Be on a parent page (example:
id: 64ab5c1b-0e3c-42f1-8692-96fabdb5a0dd
) - Have templating that outputs any of the child page data
- Output to have child
id
(example:8afc0251-58f1-4e12-983d-34248504ab8d
)
Content (tree)
tree:
-
entry: 45158ec1-b72e-4cec-8604-d66cd1400d9d
-
entry: 64ab5c1b-0e3c-42f1-8692-96fabdb5a0dd
children:
-
entry: 8afc0251-58f1-4e12-983d-34248504ab8d
[Attempted] Templating
NB: I'd like all the child data, but for simplicity here I'm just reaching for id
{{ children }}
{{ id }}
{{ children }}
or
{{ nav :from="id" }}
{{ children }}
<div>children: {{ id }}</div>
{{ /children }}
{{ /nav }}
or
{{ page:children }}
<div>children: {{ id }}</div>
{{ /page:children }}
Logs
No response
Versions
Statamic 3.3.1 Pro Laravel 9.5.1 PHP 8.0.16 aryehraber/statamic-uuid 2.1.0 doublethreedigital/duplicator 2.1.1
Installation
Fresh statamic/statamic site via CLI
Additional details
No response
Yep just going through this myself...
It's right there, yet I can't figure out how to access it.
@sjclark - I had a similar problem and made a generic children tag: you can access the children of a node (entry, ..) with
$node->pages()
So for example:
<?php
namespace App\Tags;
use Statamic\Tags\Tags;
class Children extends Tags
{
public function index(): array
{
$node = $this->params->get('node');
if (!$node || !$node->id || !($pages = $node->pages())) {
return [];
}
$items = collect();
$pages->all()->each(function ($child) use (&$items) {
if (!($entry = $child->entry())) {
return;
}
if (!$entry || !$entry->published) {
return;
}
$items->push($entry);
});
return $items->toArray();
}
}
I use this tag with
{{ children :node="someEntry" }}
{{ unless no_results }}
<li>{{ title }}</li>
{{ /unless }}
{{ /children }}
Statamic 3.3.1 Pro
@wesort have you tried on the latest version?
Are you guys using the new runtime
parser?
Might be related to https://github.com/statamic/cms/issues/5565#issuecomment-1142086035
Tried using {{ %children }}
?
Are you guys using the new
runtime
parser? Might be related to #5565 (comment)Tried using
{{ %children }}
?
I get (either pair or single)
Statamic\Tags\TagNotFoundException
Could not find files to load the `children` tag.
😂 This hilarity works
{{nav_test = 0}}
{{ nav :from="url" max_depth="1" as="nav_var" }}
{{ nav_test = (nav_var | count) }}
{{ /nav }}
{{ if nav_test > 0 }}
Show Subnav
{{/if}}
any traction on this issue? Still using the nav
hack to get around this for now
{{nav_test = 0}} {{ nav :from="url" max_depth="1" as="nav_var" }} {{ nav_test = (nav_var | count) }} {{ /nav }} {{ if nav_test > 0 }} Show Subnav {{/if}}
@sjclark Bro. This actually helped me trying to figure out some logic for a more complicated sub-nav where {{ children }}
wasn't going to get the job done 😅 Thanks!
@sjclark Bro. This actually helped me trying to figure out some logic for a more complicated sub-nav where
{{ children }}
wasn't going to get the job done 😅 Thanks!
😂 likely better ways to do it these days, but glad it helped regardless