![]() |
Declare template variable for use in header. - Printable Version +- MyBB Community Forums (https://community.mybb.com) +-- Forum: Extensions (https://community.mybb.com/forum-201.html) +--- Forum: Plugins (https://community.mybb.com/forum-73.html) +---- Forum: Plugin Development (https://community.mybb.com/forum-68.html) +---- Thread: Declare template variable for use in header. (/thread-158614.html) |
Declare template variable for use in header. - jasonw749 - 2014-09-03 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? RE: Declare template variable for use in header. - pavemen - 2014-09-03 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 RE: Declare template variable for use in header. - jasonw749 - 2014-09-03 (2014-09-03, 11:30 PM)pavemen Wrote: Use the pre_output_page or post_output_page hooks output_page function in functions.php That's a very interesting way to do it, i will have a look, thanks ![]() RE: Declare template variable for use in header. - Destroy666 - 2014-09-03 You can also use the new global_intermediate hook (if the code is for 1.8 only): https://github.com/mybb/mybb/blob/feature/global.php#L436 Everything you may need is defined before it - $templates, $theme, etc. And every template is eval'd after it. RE: Declare template variable for use in header. - jasonw749 - 2014-09-03 (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/feature/global.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 ![]() that sounds like a nice hook, i will consider updating ![]() is 1.8 a dev version? i'm quite new to MyBB so i'm unfamiliar with the update system ![]() EDIT: sorry, just seen on the site that 1.8 was released 3 days ago ![]() ![]() RE: Declare template variable for use in header. - Destroy666 - 2014-09-04 (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 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 RE: Declare template variable for use in header. - pavemen - 2014-09-04 (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/feature/global.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. |