1

I am building a module and I am looping thru data to set a value for each key, to be used as EE template tags.

foreach($missing_fields as $field)
{
    $count++;

    $vars = array(
        'field_id'              =>  $field->m_field_id,
        'field_name'            =>  $field->m_field_name,
        'field_label'           =>  $field->m_field_label,
        'field_type'            =>  $field->m_field_type,
        'field_list_items'      =>  format_list_items($field->m_field_list_items),
        'count'                 =>  $count,
        'total_fields'          =>  count($missing_fields),
    );

    $out .= $this->EE->TMPL->parse_variables_row($this->EE->TMPL->tagdata, $vars);
}


return $out;

In the template, I want to display the field's label, which works, when it is a select field (notice conditional), I want to be able to loop thru the values.

{exp:module_name:form}

    <label>{field_label}</label>

    {if field_type == "select"}
    <select name="{field_name}"
        {field_list_items}
            {!-- loop thru each select value --}
            <option value="{select_item}">{select_item}</option>
        {/field_list_items}
    </select>
    {/if}

{/exp:module_name:form}

I created a format_list_items helper function that just returns a basic array of data for testing purposes.

return array('value 1', 'value 2');

I looked at the user module to see if they did anything like this in the profile edit functions & also looked at EE's myaccount.php line 364 (in edit_profile function).

1

Tag pairs need to be formatted correctly as an array of arrays like this. Just think of the tag pair as a module tag, and the arrays as the $vars variable in your example above.

$field_list_items = array(
    array('select_item' => 'value 1'),
    array('select_item' => 'value 2'),
    ...
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.