Declare template variable for use in header.
#1
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?
Reply
#2
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
Lost interest, sold my sites, will browse here once in a while. It's been fun.
Reply
#3
(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
Reply
#4
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.
Reply
#5
(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
Reply
#6
(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
Reply
#7
(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.
Lost interest, sold my sites, will browse here once in a while. It's been fun.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)