key access in opt:section #10

Open
Skrupellos opened this Issue Sep 15, 2011 · 0 comments

Comments

Projects
None yet
1 participant

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;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment