ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Global variables and Superglobals in Templates? - Implementation problem

January 08, 2008 11:35pm

Subscribe [3]
  • #16 / Jan 10, 2008 11:00am

    radar77

    28 posts

    If I were to include the $SESS variables in a plugin, it would then be available to any template, correct? If I were not to use a plugin, where is the best place to include the code so that it would be available across templates, or is the plugin method the only way?

    Thanks for all your help Derek.

    Cheers

  • #17 / Jan 10, 2008 11:02am

    Derek Jones

    7561 posts

    As long as you are referencing the global $SESS class object, it can be used anywhere in the application.

  • #18 / Jan 10, 2008 1:35pm

    radar77

    28 posts

    Derek,

    Ok, I think I’m getting close. I am now using the $SESS class as you recommended.
    I have an index template in a template group called “press_kit.” Within this index template, I am using the embed tag to include the code that establishes the $SESS variables, which resides in a template called “webalias” in a template group called “includes.” Then, in “press_kit/index” I am just testing the variables using var_dump.

    When it is setup this way, I get undefined for all the variables. However, if I move the code in “includes/webalias” directly into “press_kit/index,” everything works as expected.

    Here is the code in “includes/webalias”

    <?php
    
    global $SESS;
    global $IN;
    
    //vars
    $SESS->cache['radar']['web_alias']="";
    $SESS->cache['radar']['fs_refer']="";
    $SESS->cache['radar']['host_refer']="";
    
    //Find out where the user came from
    $SESS->cache['radar']['fs_refer'] = $IN->GBL('HTTP_REFERER', 'SERVER'); 
    
    if (($SESS->cache['radar']['fs_refer'] == false) OR ($SESS->cache['radar']['fs_refer'] == "")){
    
        $SESS->cache['radar']['web_alias'] = "grace";
        
    } else {
    
        $SESS->cache['radar']['host_refer'] = parse_url($SESS->cache['radar']['fs_refer']);
        $SESS->cache['radar']['host_refer'] = $SESS->cache['radar']['host_refer']['host'];
        $SESS->cache['radar']['fs_refer'] = explode("=", $SESS->cache['cleure']['fs_refer']);
    
           //Set the WebAlis for outbound links back to mydomain.com
           if (($host_refer == "www.mydomain.com") OR ($fs_refer == "mydomain.com")) {
    
             $SESS->cache['radar']['web_alias']  = $SESS->cache['radar']['fs_refer'][1];
    
            } else {
    
             $SESS->cache['radar']['web_alias']  = "grace";
    
            } 
    
    
    }
    ?>

    Testing the variables:

    <?php
    global $SESS;
    
    echo 'fs_refer:
    ';
    var_dump($SESS->cache['radar']['fs_refer']);
    echo "
    ";
    
    echo 'host_refer:
    ';
    var_dump($SESS->cache['radar']['host_refer']);
    
    echo '
    web_alias:
    ';
    var_dump($SESS->cache['radar']['web_alias']);
    
    ?>

    I’m clearly doing something wrong, but am not sure at this point what is.

  • #19 / Jan 10, 2008 1:57pm

    Derek Jones

    7561 posts

    I have an index template in a template group called “press_kit.” Within this index template, I am using the embed tag to include the code that establishes the $SESS variables,

    Embeds are not parsed until after everything in the parent template is parsed.  Embedded templates cannot affect content on their parent template.

    My suggestion would be to open a new thread in the Plugin Tech assistance forum, share your code, and ask for assistance from the community in helping you turn it into a plugin.

  • #20 / Jan 10, 2008 2:30pm

    radar77

    28 posts

    Ah, I see.
    I’m going to make a post, as you recommend, over in the Plugin Tech forum.
    Thanks for all your help thus far.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases