MyBB Community Forums

Full Version: Can I use a theme template in an ACP module plugin ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi 
I'm building a massive plugin that requires a full module to configure and edit it's properties got the relevant stuff coded (module-meta.php & the css file) then I started on the modules themselves & thought it would be cool to use the template class to help render the pages .. produced a global template and hey presto it worked fine, I would prefer to have the ACP templates in the theme rather than in global ... tried that and it did not work. so the question is :- Is there a way that the template class can be forced to draw it's templates from a given theme or is there a way of producing a template set for the ACP rather than using global ?
For the ACP, you mostly use the class $page. You use that for navtabs, header, footer, and probably some other stuff. The admin cp also has classes for DefaultForm, FormContainer that you should also be aware of as they make creating forms a lot more consistent. You can use raw HTML in your PHP files for it to output, but the template class would be really unusual since admin themes are largely CSS Edits.
(2021-02-21, 03:28 AM)dragonexpert Wrote: [ -> ]For the ACP, you mostly use the class $page.  You use that for navtabs, header, footer, and probably some other stuff.  The admin cp also has classes for DefaultForm, FormContainer that you should also be aware of as they make creating forms a lot more consistent.  You can use raw HTML in your PHP files for it to output, but the template class would be really unusual since admin themes are largely CSS Edits.

what i was sort of getting at is I can use this much code 
defined(
    'IN_MYBB'
) or die('Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.');
    global $mybb,$templates,$lang;
	$settings = $mybb->settings;
	$user = $mybb->user;
	$config = $mybb->config;
	
    require_once( 'inc/class.dbquick.php' ); // load the class
	define( 'DB_HOST', $settings['phpgsm_host'] ); // set database host
    define( 'DB_USER', $settings['phpgsm_user'] ); // set database user
    define( 'DB_PASS', $settings['phpgsm_password'] ); // set database password
    define( 'DB_NAME', $settings['phpgsm_db'] ); // set database name
        
   
	$rdb = new db();
	$page->add_breadcrumb_item('PHPgsm', 'index.php?module=phpgsm');
    $page->add_breadcrumb_item('Parent Servers', 'index.php?module=phpgsm-servers');
    $page->output_header('PHPgsm Parent Servers');
    $sql = 'SELECT * from base_servers where enabled = 1 and extraip=0';
	$bases = $rdb->get_results($sql);
	foreach ($bases as $base) {
		// init templates
		 $fname = $base['fname'];	
		 eval("\$hardware .=  \"".$templates->get("phpgsm_base_server_hardware")."\";"); 
		 eval("\$software .=  \"".$templates->get("phpgsm_base_server_software")."\";"); 
		 eval("\$disk .=  \"".$templates->get("phpgsm_base_server_disk")."\";"); 
		 eval("\$memory .=  \"".$templates->get("phpgsm_base_server_memory")."\";"); 
		 eval("\$games .=  \"".$templates->get("phpgsm_base_server_games")."\";");
		 eval("\$base_servers .= \"".$templates->get("phpgsm_base_server_bit")."\";"); 
		 unset ($hardware);
		 unset($software);
		 unset($disk);
		 unset($memory);
		 unset($games);
	}
    eval("\$content .=  \"".$templates->get("admin_phpgsm_parents")."\";"); 
	echo $content;
	$page->output_footer();

to produce  this much output 

[Image: yT83wge.png]

I could not find much in the page class to do this unless I missed a trick somewhere

There is a fix/bodge for this

  1. create a new theme call it admin
  2. open the template set of your new theme  and note the sid number in the url  eg http://localhost/mybb/admin/index.php?mo...-templates&sid=8
  3. edit or add a template within the template set
  4. in your admin module code add 
    $theme['templateset'] =8;


     5. then just load the template(s) as you normally do 
eval("\$content .=  \"".$templates->get("<template_name>")."\";"); 
      

The template class only needs the 'templateset' element of the theme array to be set to retrieve templates from that group. from my point of view I have added a plugin setting to point to the group or to keep it simple you could just add your templates to the Default templates and set  $theme['templateset'] to 1, last option is don't set the variable and store your templates in the global template section
ok how do alter the cicled items so they are different ?

[Image: KnwcBM7.png]