SUMMARY: I need to access an element in an array that is passed to a template from a module and test for it's existence.

I have a function in a module that looks like this:

function subscriptions(){
  $subscriptions = array('sub1'=>array(...unimportant data...),
                         'sub4'=>array(...unimportant data...)
  $data['subscriptions'] = $subscriptions;
  $output = $this->EE->TMPL->parse_variables_row($this->EE->TMPL->tagdata, $data);
  return $output;

and a template that looks like

{exp:my_module:subscriptions} {if subscriptions:sub4}User is subscribed to sub4{/if} {/exp:my_module:subscriptions}

but that doesn't seem to work. I want to display certain things based upon what subscriptions a user has. This is not just to iterate through and print out subscriptions.

I also tried

<?php if($subscriptions['sub4']){ echo 'User is subcribed to sub4' } ?>

and it says subscriptions isn't set.

2 Answers 2


If you want your variables to be in the subscriptions:sub4 format, you should try this:

foreach ($subscriptions as $key => $value) {
  $data['subscriptions:'.$key] = $value;
return $this->EE->TMPL->parse_variables_row($this->EE->TMPL->tagdata, $data);

Rob's got it - but just to elaborate, the code you're using in your question would require you to use template code which looks like this:

        {if sub4}User is subscribed to sub4{/if}

The "colon" shortcut which EE uses in Grid and Relationship fields is not a default feature of the parse_variables() methods.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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