2015-11-09, 07:24 AM
Hey all,
Ive been having some trouble wrapping my head around exactly how to get a template into another template through the use of a variable. ill show you what I mean: (by the way if you see any glaring issues please let me know. this is my first time making a plugin)
I can define my templates no problem:
I can put a variable into a preexisting template:
and i can even get the template into the variable sometimes:
The question I have about this is how to determine which hook to use?
For my example, the 'newthread_start' hook worked because I was modifying something on the newthread.php page
But when i tried to modify the buttons at the bottom of a post on showthread.php:
http://pixs.ru/showimage/Untitledpn_8637...441257.png
doing the exact same code as above (except substituting newthread for showthread) did not work. why is this?
The following code is exactly what I have:
In the postbit template (i think that is the one responsible for rendering the aformentioned buttons):
the template has also been set up:
but for some reason this code does not result in any changes, like it did before:
I appoligise for my poor english it is not my first language
Ive been having some trouble wrapping my head around exactly how to get a template into another template through the use of a variable. ill show you what I mean: (by the way if you see any glaring issues please let me know. this is my first time making a plugin)
I can define my templates no problem:
function contrib_install()
{
//create templates
$template = '<b>Template!</b>';
$insert_array = array (
"title" => "template_name",
"template" => $db->escape_string($template),
"sid" => "-1",
"version" => "1.0",
"dateline" => time()
);
$db->insert_query('templates', $insert_array);
}
and they show up in the global template listI can put a variable into a preexisting template:
function contrib_activate()
{
require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets(
"newthread",
"#" . preg_quote('{$posticons}') . "#i",
'{$variable}
{$posticons}'
);
}
and that too goes off without a hitchand i can even get the template into the variable sometimes:
$plugins->add_hook("newthread_start","function_one");
function function_one()
{
global $templates, $variable;
$variable = eval($templates->render('template_name'));
}
And this goes off without a hitch, all fine and dandy.The question I have about this is how to determine which hook to use?
For my example, the 'newthread_start' hook worked because I was modifying something on the newthread.php page
But when i tried to modify the buttons at the bottom of a post on showthread.php:
http://pixs.ru/showimage/Untitledpn_8637...441257.png
doing the exact same code as above (except substituting newthread for showthread) did not work. why is this?
The following code is exactly what I have:
In the postbit template (i think that is the one responsible for rendering the aformentioned buttons):
...
<div class="postbit_buttons post_management_buttons float_right">
{$extra_button}
...
the variable extra_button has been addedthe template has also been set up:
function contrib_install()
{
$template = '<a id="edit_post_40" class="postbit_edit" title="Extra Button" href="TODO"> <span>Extra Button!</span> </a>';
$insert_array = array (
"title" => "button_template",
"template" => $db->escape_string($template),
"sid" => "-1",
"version" => "1.0",
"dateline" => time()
);
$db->insert_query('templates', $insert_array);
}
resulting in a very simple template.but for some reason this code does not result in any changes, like it did before:
$plugins->add_hook("showthread_ismod", "add_button"); //used to put the approved button into the showthread template if you are a mod
function add_button()
{
global $templates, $extra_button;
$extra_button = eval($templates->render('button_template'));
}
Thoughts?I appoligise for my poor english it is not my first language