statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
3.7k stars 508 forks source link

Children Tag Selection in Collection Tag Results #10505

Closed conradfuhrman closed 1 month ago

conradfuhrman commented 1 month ago

Bug description

When using the collection tag, then referencing the children tag within the results will throw an error.

How to reproduce

Take a collection and with a result use the children tag.

{{ collection:ipad :slug:is="get:page | replace('/', '')"  }}

  <p>
    {{ children }}
      <a href="{{ url }}">{{ title }}</a><br>
    {{ /children }}
  </p>

{{ /collection:ipad }}

Logs

No response

Environment

Environment
Application Name: Laravel
Laravel Version: 11.15.0
PHP Version: 8.3.9
Composer Version: 2.7.7
Environment: local
Debug Mode: ENABLED
URL: lifewavekiosk.test
Maintenance Mode: OFF
Timezone: UTC
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: reverb
Cache: database
Database: sqlite
Logs: stack / single
Mail: log
Queue: database
Session: database

Statamic
Addons: 0
Sites: 2 (English, Spanish)
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 5.17.0 PRO

Installation

Fresh statamic/statamic site via CLI

Additional details

This is a workaround;

{{ collection:ipad :slug:is="get:page | replace('/', '')"  }}
  {{ collection:ipad :parent:is="id" }}
    <ul>
      <li>{{ title }}</li>
    </ul>
  {{ /collection:ipad }}
{{ /collection:ipad }}

But it would be nice to map the children tag when called within a collection to have the same expected results.

ryanmitchell commented 1 month ago

under the hood the children tag is just doing a {{ nav from="{url}" max_depth="1" }} so you could just do that instead as a workaround.

duncanmcclean commented 1 month ago

The {{ children }} tag is only intended to let you list the children of the current page. It won't work as expected inside a collection loop.

Under the hood, it's literally just doing this.

{{ nav:collection:pages :from="current_url" max_depth="1" }}
    {{ title }}
{{ /nav:collection:pages }}

In your context, you can swap out current_url for url and it should do what you're after.