I want to draw some templates in overall hooks, but my code is not good.
Here is the link of the file is the plugin code on
GitHub.
I can be doing wrong?
PS: I'm new to github, so do not know how it works very well.
First off, the plugin file doesn't add the "pmpopup_link" template to the DB (perhaps you will add that later?) so I'm unsure what the issue may be.
Also, you shouldn't eval'd templates at global_start, use global_end instead and replace some string with your content (str_replace), this will save you one query if you add your template to the $templatelist variable (which you actually do).
But if the template "pmpopup_link" I believe in the installation of the plugin, look:
$PL->templates(
'pmpopup',
'PM Popup',
array(
'' => 'This is the PM Popup template.',
'link' => '<a id="pmpopupl" href="{$mybb->settings[\'bburl\']}/private.php">{$ppmp[\'unread\']}</a>',)
);
And not quite understand that using str_replace in global_end, as would be?
You hook at global_end and replace a string with your template.
function foo()
{
global $header, $templates;
eval('$bar = "'.$templates->get('pmpopup_link').'";');
$header = str_replace('<!--STRING-->', $bar, $header);
}
To make it simple, you add your template to the $templatelist at global_start, anything else should be done at global_end.
function foo()
{
global $header, $templates;
if($mybb->user['pms_unread'] == 1)
{
$ppmp['unread'] = 'Tienes <strong>1</strong> mensaje privado sin leer.';
}
else
{
$ppmp['unread'] = "Tienes <strong>{$mybb->user['pms_unread']}</strong> mensajes privados sin leer.";
}
eval('$bar = "'.$templates->get('pmpopup_link').'";');
$header = str_replace('<!--STRING-->', $bar, $header);
}
I do not understand where is the replacement?
Because global_start say that the templates are already defined in $templatelist?
Could you let me the code as is?
Well, I have managed do half of what I need
But only shows me the template, but not the contents that should go on this.
Updated the code to be seen ..
https://github.com/Steeep/PmPopup/commit...d088a0ebd6
Quote:Because global_start say that the templates are already defined in $templatelist?
Yes because you add your template to the list before global_start is run, you can just skip it in this case.
Quote:But only shows me the template, but not the contents that should go on this.
That is because $header is not eval'd until after global_start is run. You need to move your code from global_start to global_end.