Changing Default Forumbit in forumlist
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #4
RE: Changing Default Forumbit in forumlist
A core edit is definitely the simplest approach.  The plugin API gives you points of access, but it's often actually difficult to modify behavior.

The proposed method of having multiple templates may be problematic due to how PHP scopes variables (some variables may be unavailable to you).

Some methods I can think of, using the plugin system, to achieve this:
  • Overriding the $templates->cache store, example:

    PHP Code:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    $plugins->add_hook("build_forumbits_forum", "plugin_forumbits");
    function plugin_forumbits($forum)
    {
    	global $mybb, $templates;
    	static $revert = null;
    	$tpl = array('forumbit_depth1'); // list all the templates you wish to override here
    	
    	if(!isset($revert)) {
    		// initialisation code
    		
    		$tpl_a = array();
    		foreach($tpl as $t) $tpl_a[] = $t.'_a';
    		
    		$templates->cache(implode(',', $tpl_a)); 
    		// backup copy of templates
    		foreach($tpl as $t)
    			$templates->cache['__plugin_'.$t] = $templates->cache[$t];
    		
    		$revert = false;
    	}
    	
    	if($forum['type_a'] == 1) {
    		// do template hack
    		foreach($tpl as $t)
    			$templates->cache[$t] = $templates->cache[$t.'_a'];
    		$revert = true;
    	}
    	elseif($revert) {
    		// revert template hack
    		foreach($tpl as $t)
    			$templates->cache[$t] = $templates->cache['__plugin_'.$t];
    		$revert = false;
    	}
    }

  • Putting a placeholder in the template which you replace (perhaps using regex) later on
  • Dynamically extending (ala control_object) the $templates object - this is what XThreads / Template Conditionals does

Hope that gives you ideas should you wish to try out doing it through a plugin again.

My Blog
(This post was last modified: 08-14-2013 08:25 PM by ZiNgA BuRgA.)
08-14-2013 08:17 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
RE: Changing Default Forumbit in forumlist - ZiNgA BuRgA - 08-14-2013 08:17 PM

 Standard Tools
Forum Jump: