Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Children tag pair doesn't return as expected #5567

Closed
wesort opened this issue Mar 18, 2022 · 9 comments · Fixed by #8990
Closed

Children tag pair doesn't return as expected #5567

wesort opened this issue Mar 18, 2022 · 9 comments · Fixed by #8990
Labels

Comments

@wesort
Copy link
Sponsor Contributor

wesort commented Mar 18, 2022

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:
image

? Related to #5554
? Related to #5565

How to reproduce

  1. Be on a parent page (example: id: 64ab5c1b-0e3c-42f1-8692-96fabdb5a0dd)
  2. Have templating that outputs any of the child page data
  3. 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

@sjclark
Copy link
Contributor

sjclark commented Mar 25, 2022

Yep just going through this myself...
Screen Shot 2022-03-25 at 5 46 38 pm

It's right there, yet I can't figure out how to access it.

@naabster
Copy link

@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 }}

@edalzell
Copy link
Contributor

Statamic 3.3.1 Pro

@wesort have you tried on the latest version?

@joshuablum
Copy link
Member

Are you guys using the new runtime parser?
Might be related to #5565 (comment)

Tried using {{ %children }}?

@sjclark
Copy link
Contributor

sjclark commented Aug 19, 2022

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. 

@sjclark
Copy link
Contributor

sjclark commented Mar 31, 2023

😂 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}}

@ozmos
Copy link

ozmos commented Sep 6, 2023

any traction on this issue? Still using the nav hack to get around this for now

@rhettparkinson
Copy link

{{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
Copy link
Contributor

sjclark commented May 15, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants