Access IDs inside perch:repeater array?

  • Hi,


    I have a hero banner, which allows admin to pick a featured event from a collection. It works but I need to do some other things with it.


    The events--hero.html template has this perch:related id="feat_event" tag, using perch_content_custom I need access to the IDs inside perch:related


    This is what I have so far:

    PHP
    1. $feat_event = perch_content_custom('Hero', [
    2. 'template' => '_events/hero/events--hero.html',
    3. 'skip-template' => true,
    4. 'return-html' => true,
    5. ]);
    6. $feat_event_hero = $feat_event[0]['feat_event'];
    7. pipit_r ($feat_event_hero);

    Unfortunately, $feat_event_hero only displays this array:

    Code
    1. Array
    2. (
    3. [0] => 9
    4. )


    This is my events--hero.html template. If I place <perch:showall> inside perch:related I can see all the IDs.

    HTML
    1. <perch:related id="feat_event" collection="Events" max="1">
    2. <perch:showall>
    3. <!-- Template IDs here... -->
    4. </perch:related>


    Is there a way to access the IDs inside perch:related id="feat_event"? using perch_content_custom:/

  • Off the top of my head here so apologies for not showing code but could you use the 'each' option containing a collection function that calls a single related collection item with the related id using 'event._id'?


    You can then return the id from that collection into the perch_custom_content function results and pick it up from there.

  • Is there a way to access the IDs inside perch:related id="feat_event"? using perch_content_custom :/

    In PHP, you need to fetch the item with perch_collection(). perch:related does this for you inside the template. If you skip the templating, you need to do this yourself: