3

I'm trying to do something like the following:

{exp:my_tag my-param2="1" my-param2="2"}
    <li>{title}</li>
    <li><ul>
    {my_fields}
        <li>{field_label}: {field_value}</li>
    {/my_fields}
    </ul></li>
{/exp:my_tag}

Is it possible to do it with a simple TMPL->parse_variables() or should I put in place something more complex?

5

The parse_variables function handles this natively so there's really no need to complicate things unless you need some additional functionality.

The template class documentation includes some detailed instructions, but basically you just need to add a my_fields array to your main array of variable data.

$vars['title'] = 'My Title';

$vars['my_fields'] = array(
    array('field_label' => 'Foo', 'field_value' => 'Something'),
    array('field_label' => 'Bar', 'field_value' => 'Something else')
);

$output = $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $vars);
  • Thanks Dom, I was stuck with the fact that I had to make a 3D array, but it works well. – pvledoux Dec 3 '12 at 14:20

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.