We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Global conditional variable via EE API

Development and Programming

thisconnect.be's avatar
thisconnect.be
73 posts
13 years ago
thisconnect.be's avatar thisconnect.be

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!

       
Shane Eckert's avatar
Shane Eckert
7,174 posts
13 years ago
Shane Eckert's avatar Shane Eckert

Hey thisconnect.be,

I am going to move this thread over to Development and Programming for you!

The community there will take care of you.

Cheers,

       
the3mus1can's avatar
the3mus1can
426 posts
13 years ago
the3mus1can's avatar the3mus1can

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}
       
thisconnect.be's avatar
thisconnect.be
73 posts
13 years ago
thisconnect.be's avatar thisconnect.be

I ended up writing an extension that runs on the sessions_start hook. The extension adds a new global var that I can use inside my templates. Problem solved, thank you for your help!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.