MyBB Community Forums

Full Version: Using Templates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,
This is my first post here. I have problems with using templates. I managed to create a new template using template manager. But I haven't managed to find out how to use this template in the other templates. I mean how to include the new templates into the existing templates.
Thanks in advance...
Br,
winnie2
You would need PHP:

eval("\$variable = \"".$templates->get('template_name')."\";");

Put $variable in the template you'd want it to show. Where do you need it??
(2010-02-21, 10:03 PM)MattRogowski Wrote: [ -> ]You would need PHP:

eval("\$variable = \"".$templates->get('template_name')."\";");

Put $variable in the template you'd want it to show. Where do you need it??

Hi MattRogowski,
Thanks for the quick reply.
I need to use them in the header and footer templates. Can I use php there?
Not in the templates but I could make you a little plugin to show it if you could give me a name that would suit what the code is about.
Ok I gonna be more precise:
So what I am trying to do is putting the language switcher in the header instead of the footer cause of my visitors are really international. My first thing I tried to use {$lang_select} in the header, but it didn't work. My second try was includeing footer_languageselect in the header, no success. I also tride to copy footer_languageselect into header_languageselect and include that file, still no success.

Thx,

winnie2
Anyone any solution? I really need this to be fixed asap...
Still looking for the solution. I overgoogled everything, without any success....
Winnie2,

the main problem with using the "language switcher in the header" is because in the global.php file the construction of the language box is done before the $footer is completed but after the $header is already completed.

So to make it work in the header, you have to move in your global.php file this line :

eval("\$header = \"".$templates->get("header")."\";");

After the $lang_select construction:

// Are we showing the quick language selection box?
$lang_select = '';
if($mybb->settings['showlanguageselect'] != 0)
{
    $languages = $lang->get_languages();
    foreach($languages as $key => $language)
    {
        $language = htmlspecialchars_uni($language);
        // Current language matches
        if($lang->language == $key)
        {
            $lang_options .= "<option value=\"{$key}\" selected=\"selected\">&nbsp;&nbsp;&nbsp;{$language}</option>\n";
        }
        else
        {
            $lang_options .= "<option value=\"{$key}\">&nbsp;&nbsp;&nbsp;{$language}</option>\n";
        }
    }
    
    $lang_redirect_url = get_current_location(true, 'language');
    
    eval("\$lang_select = \"".$templates->get("footer_languageselect")."\";");
}


So this way your new "header template" containing this section:

<form method="{$lang_redirect_url['form_method']}" action="{$lang_redirect_url['location']}" id="lang_select">
		{$lang_redirect_url['form_html']}
		<select name="language" onchange="MyBB.changeLanguage();">
			<optgroup label="{$lang->select_language}">
				{$lang_options}
			</optgroup>
		</select>
		{$gobutton}
</form>

will properly work.
Thanks a lot, that really helped