Forum

Thread tagged as: Question

Undefined index: perch_item_index

Hi, I am pulling in some content for a region using 'skip-template' => true.

I am then pulling in the data using the below to output json.

if (count($mydata)) {
          $out = [];
          foreach($mydata as $datum) {
            $item = [];
            $item['number'] = $datum['perch_item_index'];
            $item['client'] = $datum['client'];
            $item['title'] = $datum['title'];
            $item['user'] = $datum['user'];

            $out[] = $item;
          }

          echo json_encode($out);
        }

I am getting the following error using debug:

Array
(
    [type] => 8
    [message] => Undefined index: perch_item_index
    [file] => /var/www/sitename/index.php
    [line] => 53
)

Does perch_item_index become unusable when bypassing the template?

Andy Knight

Andy Knight 1 points

  • 2 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_item_index is generated by the template engine, so it's not available here.

Thanks Drew.

So is there any way to create a unique id for a group of items in a multi item region?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You're in a loop, so you can use a variable counter. That's all perch_item_index is.