Hello everyone,
I’m trying to set a global conditional variable in the module I’m developing so I can use it in my templates. I want this conditional variable to check if my user is authenticated to a webservice I’m calling…
So you might say it needs some kind of the same functionality as the {logged_in} conditional variable.
Can anyone help me to get this done via the EE API? Or do I have to do this another way?
Thanks!
Where and how you do this is going to largely depend on parse order.
To add a global variable to be parsed that is dynamic you can add it to _global_vars like this:
$this->EE->config->_global_vars['variable_name'] = $variable_value;But you cannot do this inside of your module because its code is executed after the template parser parses the global variables. To use this technique you will have to add a variable to the _global_vars array in an extension that runs on maybe session_start. However, if you don’t want to write an extension and keep all this in your module you can create a module tag that wraps the entire page and parsers a conditional variable. Something like:
public function call_service()
{
///other cool code...
$variables = array(
'is_logged_in' => TRUE,
);
return $this->EE->functions->prep_conditionals($this->EE->TMPL->tagdata, $variables);
}This would result in template usage like:
{exp:your_module:call_service}
{if is_logged_in}
{/if}
{/exp:your_module:call_service}Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.