MyBB Community Forums

Full Version: Use {$[something]} instead of long code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I hate editing codes for 6 different templates everytime somebody adds an affiliate link, so is there a way to just use {$affiliation_box} instead of
<!-- start: affiliation_box -->
<table width="100%" border="0" cellspacing="1" cellpadding="4" class="tborder">
<thead>
<tr>
<td class="thead">
<div class="expcolimage"><img src="{$theme['imgdir']}/collapse.gif" id="welcome_img" border="0" class="expander" alt="[-]" /></a></div>
<div><strong>Affiliates & Partner Websites</strong></div>
</td>
</tr>
</thead>
<tbody style="" id="welcome_e">
<tr><td class="trow1">
<b><center><a href="http://www.creativehoster.net" target="_blank">Creative Hoster - #1 Web Host</a></center></b>
<marquee onmouseover="this.setAttribute('scrollamount', 0, 0);" onmouseout="this.setAttribute('scrollamount', 6, 0);" scrolldelay="100"><a href="http://theeilforums.co.nr" target="_blank">The Eil</a>, <a href=" http://red-king.org" target="_blank"">Legend of the Red King</a>, <a href="http://www.gamechaser.net/" target="_blank" target="_blank">Gamechaser.net</a>, <a href="http://www.animemaniax.uni.cc/" target="_blank">Anime Maniax</a>, <a href="http://www.nyxonline.com" target="_blank">Nyx Online</a>, <a href="http://www.adzfolio.com/" target="_blank">ADZ Folio</a>, <a href="http://pccom.info/" target="_blank">PCCom.info</a>, <a href="http://www.thatonenation.com/" target="_blank">That One Nation</a>, 
<a href="http://www.mybbstyles.net/portal.php" target="_blank">MyBB Styles</a>, <a href="http://www.mybbworkshop.co.cc/" target="_blank">MyBB Workshop</a></marquee></td></tr>
</tbody>
</table>
<br/>
<!-- end: affiliation_box -->
I want it so that the template is in the Global Templates so that I only need to edit one template and have effect on all other templates.
Add your global template then go and edit global.php in your forum's root directory.

Because this involves editing source code, backup your forum before making this change. If you don't want to edit the source code, then you can always make a plugin (if you can) that uses the hook "global_end", or something similar.

You can make the code like this:

// Adding a global template
eval("\$mytemplate = \"".$templates->get("mytemplatename")."\";");

// Run hooks for end of global.php
$plugins->run_hooks("global_end");

$mytemplate is the variable you will call in other templates, mytemplatename is the name of your global template.

Hope this helps. Like I said, if you intend on this being a "lifetime" change for your forum (as in, you'll be using this all the time), then I reckon you should arrange for a plugin to be made. If you don't, you'll need to make this change everytime global.php is updated in a MyBB upgrade.

You can also call conditionals around it. For example, if you use if(!$mybb->user['uid']){ before the eval then only your guests you can see it. The possibilities are endless, or so the advert goes...

Smile
Thanks, I'll attempt to make a plugin then.