Jump to the post that solved this thread.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solved: 3 Years, 7 Months, 1 Week ago Including CSS style definitions from within a plugin
#1
Solved: 3 Years, 7 Months, 1 Week ago
Hi,

Am new to MyBB. Am trying to create a plugin. The thing that am having doubt now is how to include some css styles(10 lines max) in the header or anywhere in the page, without the admin to manually edit any template files?

I saw that there are several hooks available. But am having which one to be used as there's no description in that list!

Highly appreciate any suggestions or ideas.

Thank you
Reply
#2
Solved: 3 Years, 7 Months, 1 Week ago
If I were you, I'd have your plugin modify the header_include template on activation. Note that this template is included on all pages. If you want, you could even reference an external style sheet (could even point to a PHP file to dynamically create the CSS).
Reply
#3
Solved: 3 Years, 7 Months, 1 Week ago
You can install css files of a plugin on this way:
// add css file of plugin
	$css_array = array(
	"name" => "cssname.css", // name of css file - ends with .css
	"tid" => 1, 
	"attachedto" => "", // script name the css should be attached to (splitted by | ) - empty for all sites
	"stylesheet" => "", // stylesheet definitions
	"cachefile" => $db->escape_string(str_replace('/', '', cssname.css)),
	"lastmodified" => TIME_NOW
	);
	require_once MYBB_ADMIN_DIR."inc/functions_themes.php";
	$sid = $db->insert_query("themestylesheets", $css_array);
	$db->update_query("themestylesheets", array("cachefile" => "css.php?stylesheet=".$sid), "sid = '".$sid."'", 1);
	$tids = $db->simple_select("themes", "tid");
	while($theme = $db->fetch_array($tids))
	{
		update_theme_stylesheet_list($theme['tid']);
	}



// remove added css file of plugin
	$db->delete_query("themestylesheets", "name = 'cssname.css'");

	require_once MYBB_ADMIN_DIR."inc/functions_themes.php";
	$query = $db->simple_select("themes", "tid");
	while($theme = $db->fetch_array($query))
	{
		update_theme_stylesheet_list($theme['tid']);
	}
Greetings Sven (ps: Sorry for my bad english!!)

My plugins - [email protected]
Reply
#4
Solved: 3 Years, 7 Months, 1 Week ago
Thanks you very much for the response.

Can you guide me what should be done if I wanted to inject JS ? I mean some jQuery code I wished to be included.
Reply
#5
Solved: 3 Years, 7 Months, 1 Week ago
There is more than one way to include JS with a plugin. You could make it directly on this way: http://docs.mybb.com/1.8/development/plu...-templates
Greetings Sven (ps: Sorry for my bad english!!)

My plugins - [email protected]
Reply
Jump to the post that solved this thread.


Forum Jump:


Users browsing this thread: 1 Guest(s)