x
 
Create New Page
 View Previous Changes    ( Last updated by Erik Stainsby )

Using your own templates in member templates

This is how to parse your own templates and have them appear within your member templates in EE 1.6x.

In any of the functions in profile_theme.php - such as html_footer() - you can do the following:

require PATH_CORE.'core.template'.EXT;            
    
$T = new Template();     
global 
$TMPL$OUT;
$TMPL $T;

$TMPL->run_template_engine('my_template_group''my_template');

$parsed_template $OUT->out_queue;

return 
$parsed_template

Very handy for reusing the footer/header templates used elsewhere in your site.

A more efficient alternative is to load the template class in the profile_theme constructor, like so:

//-------------------------------------
//  Constructor
//-------------------------------------
function profile_theme()
{        
    
    
// instantiate and overwrite the existing global
    
global $TMPL;
    
    if (!
class_exists('Template'))
    
{    
        
// load EEs template parser
        
require_once PATH_CORE.'core.template'.EXT;    
        
$T = new Template();     
       
           
$TMPL $T;
    
}

Thereafter you can simply declare the $TMPL global and run the run_template_engine() method, eg:

function html_footer()
{
    
global $OUT$TMPL;

    
$TMPL->run_template_engine('my_template_group''my_template');

    return  
$OUT->out_queue;

Caveats:

If you are using secure forms to prevent XSS and CSRF (Admin > System Preferences > Security and Session Preferences), then you will find that the XID value is stripped from some of the member profile forms. This is because the security hash is output from the Member’s module only if the Template class has NOT been loaded. Since we’re loading the class to render our custom templates, we need a small hack to mod.member.php.

At around line 2688 find this code block:

//Add security hashes to forms
        
if ( ! class_exists('Template'))
        
{
            $str 
$FNS->insert_action_ids($FNS->add_form_security_hash($str));
        

Simply change to:

$str $FNS->insert_action_ids($FNS->add_form_security_hash($str)); 

Note that if you are using PHP 5.3+ then you should be able to use a namespace declaration at the top of profile_theme.php instead.

Related reading on topic of namespaces in PHP 5.3+:

Namespace basics
Namespace import and aliasing
Keywords and autoloading

At some point I will write up a detailed explanation of namespace uses in this context. ~ Erik

—-

Category:Members
Category:Templates

Category:EE1

Categories: