MyBB Community Forums

Full Version: Declare template variable for use in header.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Am i right in thinking there's no way to declare a global variable, assigned to a template->get that can be used in the header, through a plugin?

global_start is before templates is defined, and global_end is after the header is defined, so am i screwed? or is there something i'm missing apart from just editing the php?
Use the pre_output_page or post_output_page hooks output_page function in functions.php

you cant update a template already parsed but you can use a string replace on the already parsed template before it is output to the browser.

Like insert "<myplaceholder>" in the template you want to update, then your plugin will create a string variable that you then replace <myplaceholder> with in the HTML available in that hook
(2014-09-03, 11:30 PM)pavemen Wrote: [ -> ]Use the pre_output_page or post_output_page hooks output_page function in functions.php

you cant update a template already parsed but you can use a string replace on the already parsed template before it is output to the browser.

Like insert "<myplaceholder>" in the template you want to update, then your plugin will create a string variable that you then replace <myplaceholder> with in the HTML available in that hook

That's a very interesting way to do it, i will have a look, thanks Smile
You can also use the new global_intermediate hook (if the code is for 1.8 only): https://github.com/mybb/mybb/blob/featur...l.php#L436 Everything you may need is defined before it - $templates, $theme, etc. And every template is eval'd after it.
(2014-09-03, 11:51 PM)Destroy666 Wrote: [ -> ]You can also use the new global_intermediate hook (if the code is for 1.8 only): https://github.com/mybb/mybb/blob/featur...l.php#L436 Everything you may need is defined before it - $templates, $theme, etc. And every template is eval'd after it.

The plugin is for a personal site, not to be released, so i can go to whatever version is necessary Smile

that sounds like a nice hook, i will consider updating Smile

is 1.8 a dev version? i'm quite new to MyBB so i'm unfamiliar with the update system Smile



EDIT: sorry, just seen on the site that 1.8 was released 3 days ago Smile will update later today Smile
(2014-09-03, 11:57 PM)jasonw749 Wrote: [ -> ]is 1.8 a dev version? i'm quite new to MyBB so i'm unfamiliar with the update system Smile

No. 1.8 was released few days ago: http://blog.mybb.com/2014/09/01/mybb-1-8-released/ You can upgrade from 1.6
(2014-09-03, 11:51 PM)Destroy666 Wrote: [ -> ]You can also use the new global_intermediate hook (if the code is for 1.8 only): https://github.com/mybb/mybb/blob/featur...l.php#L436 Everything you may need is defined before it - $templates, $theme, etc. And every template is eval'd after it.

That will save a ton of effort for several plugins! Nice addition.