Trying to figure out what appears to be a global variable parse issue in a module add-on template tag.

Here's a sample of the tag used in the template:

{exp:syn_fb_comments:show url="{current_url}"}{fb_comments}{/exp:syn_fb_comments:show}

In the module, when I grab the param url:

$url = $this->EE->TMPL->fetch_param( 'url' );

My understanding is that the {current_url} tag should already be parsed as the actual URL. However, in fetching the parameter value, it returns the raw tag itself, {current_url}.

Question, is there something specific that needs to be done to have these template variables parsed before processing the tagdata for the add-on?

Assuming either I'm missing something simple here, or I'm just doing it wrong! Any insight is appreciated.

EE Version 2.5.5


3 Answers 3


I think UltraBob is right in that if you need a global variable available inside the module you need parse them inside the add-on. parse_globals() looks to be the way to do so (thanks to this answer on Stack Overflow).

The following will show that the parsed global is available in the module:

$parameter = $this->EE->TMPL->fetch_param('parameter_name');
$parameter = $this->EE->TMPL->parse_globals($parameter);
echo 'The parsed global is: ' . $parameter;
  • 1
    try to scan what the main libraries do, like the parse_globals() and parse_variables() and other methods. That way you can grasp where variables are fetched from and where they're stored. One of the powers of EE is that you have source access, use the source Luke.
    – GDmac
    Commented Feb 20, 2013 at 8:35
  • Thanks Alex! It was as simple as running the fetched parameter value through the parse_globals() method of the Template class. Completely missed that one!
    – Synergema
    Commented Feb 20, 2013 at 13:03
  • Interesting that the {current_url} is already parsed for you in the module. On my end it is not, having to run it through the parse_globals method. Not sure why that is.
    – Synergema
    Commented Feb 20, 2013 at 13:05
  • Ah, you know what it is? For older versions of EE I had a habit of adding a user-defined global variable for current_url in index.php so that's what it was. :-P Still, the docs say these are parsed after modules and plugins, but at least that explains the difference in our results!
    – Alex Kendrick
    Commented Feb 20, 2013 at 14:01

I think you either have to return global variables as they stand and let the parser handle them later on, or if you actually need to do something with them, you'd need to actually parse them inside your add-on.

The global variables are stored in $this->EE->config->_global_vars, so I guess one thing to do would be to parse through looking for {} pairs and doing something like

foreach ($matched_brace_contents as $potential_global_var) {
    if ( isset( $this->EE->config->_global_vars[$potential_global_var] )) {
        //do your worst

That is untested code, and may very well need some work, but hopefully it gives an idea of one way of checking if the curly brace pair you see is a global variable or not?

Alternatively, perhaps the Template class can do what you need without you needing to do it on your own.

  • Perhaps array_key_exists() would be better than isset()
    – UltraBob
    Commented Feb 20, 2013 at 2:28
  • 1
    Looking at the docs it seems like perhaps what your really want is the parse_variables() method of the Template class. I think I need to find the time to develop a few add-ons for EE2, and refamiliarize myself with it all.
    – UltraBob
    Commented Feb 20, 2013 at 2:34
  • 1
    Looking at your specific example, it seems like making the current url the default would make sense and remove the need for you to parse it if that case is the only one troubling you.
    – UltraBob
    Commented Feb 20, 2013 at 4:10

The answers here didn't work for me, but a simple query does. Just in case this helps soneone else...

$sql = "select variable_data from exp_global_variables where variable_name = '$glob_var' ";
$results = $this->EE->db->query($sql);
$row = $results->first_row();  //returns an object
$global_var_value = $row->variable_data;  //get result from property

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.