Skip to content
This repository was archived by the owner on May 8, 2021. It is now read-only.
This repository was archived by the owner on May 8, 2021. It is now read-only.

key access in opt:section #10

@skruppy

Description

@skruppy

Reproduction

Using Opt 2.1 beta 1 and the following template.

<select name="foo">
    <opt:section name="field" datasource="$global.fields">
        <option value="parse:u:$sys.section.field.iterator">{u:$field.name}</option>
    </opt:section>
</select>

Result

The example will compile to the following.

<select name="foo">
    <?php $_sectfield_vals = $ctx->_data['global']['fields'];  if(is_array($_sectfield_vals) && ($_sectfield_cnt = sizeof($_sectfield_vals)) > 0){  for($_sect1_i = 0; $_sect1_i < $_sectfield_cnt; $_sect1_i++){   ?>
        <option value="<?php echo $_sectfield_vals[$_sect1_i]['iterator'];   ?>"><?php echo $_sectfield_vals[$_sect1_i]['name'];   ?></option>
    <?php  }   }   ?>
</select>

But $_sectfield_vals[$_sect1_i]['iterator'] is always null.

Expected

I don't know what the variable name should be, but it definitely should
contain the key :-)

Workaround

Before you append an array to a view. extend it with the missing iterator values.

<?php
foreach($array as $key => $value) {
    $array[$key]['iterator'] = $key;
}
?>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions