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

key access in opt:section #10

Open
skruppy opened this issue Sep 15, 2011 · 0 comments
Open

key access in opt:section #10

skruppy opened this issue Sep 15, 2011 · 0 comments

Comments

@skruppy
Copy link

skruppy commented Sep 15, 2011

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant