Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: The Wizard on November 16, 2012, 11:50:50 AM

Title: Global Question
Post by: The Wizard on November 16, 2012, 11:50:50 AM
Do I need to use any globals to call up loadTemplate or not? The little voice in the back of my head says no, but who is to say the voice is right?


// Function Wizard: Loads the wizard template file

function wizard_popup ()
{

// Globals

global $smcFunc;

// this command loads the template file (wizard_popup.template.php)

    loadTemplate('wizard_popup');

} // End of Function wizard bracket



Wiz
Title: Re: Global Question
Post by: All Colours Sam on November 16, 2012, 11:54:10 AM
The file that holds loadTemplate() func its loaded on every instance of SMF, meaning you don't need to require any file to use it.

As per globals, that only affects variables, not functions, if you need to use some var like $context then you must globalize this var before you can use it.
Title: Re: Global Question
Post by: The Wizard on November 16, 2012, 12:26:23 PM
So I don't need to use any globals and code should look like this -


// place this file in the Sources file

    if (!defined('SMF'))
            die('Hacking attempt...');

// Function Wizard: Loads the wizard template file

function wizard_popup ()
{

// this command loads the template file (wizard_popup.template.php)

       loadTemplate('wizard_popup');

} // End of Function wizard bracket
Title: Re: Global Question
Post by: All Colours Sam on November 16, 2012, 12:59:06 PM
yep, providing your file is been running inside SMF atmosphere, if you're gonna use your file as an external standalone one then requiring SSI.php before anything else should be enough.