• Resolved DesktopMasters

    (@desktopmasters)


    I am very new to pods…
    I have a group of fields setup in a pod. In at template I want to cycle through the group and show the fields in the group “product_information_group”…

    So I tried…
    [each product_information_group]
    {@name}
    [/each]

    I want to list it in a table with the display name (label) of the field and the value within it. Is this something that pods supports? I do not even see the above label listed on the right panel of the template editor.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Paul Clark

    (@pdclark)

    No, it’s not currently possible to iterate over fields in a group with [each] — each is for array-type fields such as relationships and media uploads. One would have to list the fields in the template one by one or access the Group’s fields in PHP.

    Untested, but something like this might work:

    // Get the Pod object.
    $pod = pods('your_pod_name');
    
    // Get all fields for the Pod.
    $fields = $pod->fields();
    
    // Iterate through the fields.
    foreach ($fields as $field) {
        // Check if the field is part of a group.
        if ($field['group'] === 'your_group_name') {
            // Do something with the field...
            echo $field['name'] . '<br>';
        }
    }
    
    Thread Starter DesktopMasters

    (@desktopmasters)

    Thank you very much!

    I ended up getting it to work with your code. But I feel like there is a better way to get the value. It took me a minute to figure out I had to grab the number of the group and not use the name of it.

    <?php
    $pod = pods('product');
    
    $fields = $pod->fields();
    
    foreach ($fields as $field) {
        if ($field['group'] === '1724') {
            echo $field['label'] . ': {@' . $field['name'] . '}<br>';
        }
    }
    ?>
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Use [each] on a group of fields..’ is closed to new replies.