vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   How to display pm notifications in a custom template? (https://vborg.vbsupport.ru/showthread.php?t=322445)

Hilary 04-23-2016 05:54 PM

How to display pm notifications in a custom template?
 
Hi,

I've registered a custom template to include inside the header template with
Code:

{vb:raw mytemplate}
. It works... the
Code:

<vb:if condition="$show['member']">
condition inside mytemplate works, too. But
Code:

<vb:if condition="$notifications_total">
doesn't.

So if I put this code in mytemplate -
Code:

<vb:if condition="$notifications_total"><div>there are notifications</div>
<vb:else /><div>no notifications here</div>
</vb:if>

I always see 'no notifications here'.

The exact same code in the header template works as expected.

Does anyone know a solution for this?

Lynne 04-23-2016 05:57 PM

You will need to register the variable $notifications_total for use in your custom template.

Cellarius wrote a really good article that you may be interested in - [vB4] Rendering templates and registering variables - a short guide

Hilary 04-23-2016 07:24 PM

Hi Lynne! Thanks for the swift response.

I've just been reading through that thread, and I'm really glad to find you're still posting here.

I found this example code there:

Code:

$templater = vB_Template::create('memberbar_member_basic');
$memberbar_member_basic = $templater->render();
vB_Template::preRegister('navbar', array('notifications_menubits' => $notifications_menubits));
vB_Template::preRegister('navbar', array('memberbar_member_basic' => $memberbar_member_basic));
vB_Template::preRegister('navbar', array('notifications_menubits' => $notifications_menubits));

...looks like exactly what I want to do, displaying notifications in a custom template, though the op mentions it has a mistake and doesn't say what the mistake is (besides perhaps the duplicated line)...

So I took my existing plugin...
Code:

$templater = vB_Template::create('ubermenu');
$ubermenu = $templater->render();
vB_Template::preRegister('header', array('ubermenu' => $ubermenu));

and tried adding to it -
Code:

$templater = vB_Template::create('ubermenu');
$ubermenu = $templater->render();
vB_Template::preRegister('header', array('notifications_menubits' => $notifications_menubits));
vB_Template::preRegister('header', array('notifications_total' => $notifications_total));
vB_Template::preRegister('header', array('ubermenu' => $ubermenu));

No luck. Then thought this made no sense, since notifications already work in the header, it's the 'ubermenu' template that needs to know about them, so tried
Code:

vB_Template::preRegister('ubermenu', array('notifications_total' => $notifications_total));
etc instead, both in that plugin and in a separate one. Still no luck. :confused:

Help?

MarkFL 04-24-2016 02:04 AM

First, you may combine the 3 lines:

PHP Code:

vB_Template::preRegister('header', array('notifications_menubits' => $notifications_menubits));
vB_Template::preRegister('header', array('notifications_total' => $notifications_total));
vB_Template::preRegister('header', array('ubermenu' => $ubermenu)); 

as follows:

PHP Code:

vB_Template::preRegister('header', array('notifications_menubits' => $notifications_menubits'notifications_total' => $notifications_total'ubermenu' => $ubermenu)); 

However, I am thinking this is more along the lines of what you want to do:

PHP Code:

$templater vB_Template::create('ubermenu');
    
$templater->register('notifications_menubits'$notifications_menubits);
    
$templater->register('notifications_total'$notifications_total);
$ubermenu $templater->render();
vB_Template::preRegister('header', array('ubermenu' => $ubermenu)); 

This way you are registering the two variables your "ubermenu" template needs to render its output correctly, and then you can register that output (stored in $ubermenu) for use in the header template. :)

Hilary 04-24-2016 06:54 AM

Thank you.

I'm sure you're right.

**EDIT**

Er, let me just delete everything I wrote before I found the stray ' in the code :o . I still haven't got it working, but I'll post a better update after I've tested a few more things.

--------------- Added [DATE]1461490554[/DATE] at [TIME]1461490554[/TIME] ---------------

Sorry to say that this -
Code:

$templater = vB_Template::create('ubermenu');
        $templater->register('notifications_menubits', $notifications_menubits);
        $templater->register('notifications_total', $notifications_total);
$ubermenu = $templater->render();
vB_Template::preRegister('header', array('ubermenu' => $ubermenu));

- definitely doesn’t work.

I replaced my whole ubermenu template with the original notifications code, and finally with
Code:

<div><vb:if condition="$notifications_total">There are notifications<vb:else />Yes, we have no notifications</vb:if>
<ul>{vb:raw notifications_menubits}</ul></div>

It always displays the 'no notifications' option (and I'm logged in, and have loads of notifications, which show up fine in the default skin), and doesn't display the notifications_menubits at all. IOW, the presence or absence of those two 'register' lines in the plugin makes no difference to the result.

MarkFL 04-24-2016 10:04 AM

What hook location are you using for your plugin?

Hilary 04-24-2016 10:18 AM

parse_templates

(I tried 'global_start' first, but the template didn't appear at all.)

MarkFL 04-24-2016 10:22 AM

Try "global_setup_complete"...:)

Hilary 04-24-2016 10:33 AM

Nope - template disappears altogether again.

MarkFL 04-24-2016 06:45 PM

Okay, here's my workaround:

The "mytemplate" template:

HTML Code:

<div>
        <vb:if condition="$notifications_total">
                there are notifications
        <vb:else />
                no notifications here
        </vb:if>
</div>

The plugin, hooked at "process_templates_complete":

PHP Code:

$templater vB_Template::create('mytemplate');
    
$templater->register('notifications_menubits'$notifications_menubits);
    
$templater->register('notifications_total'$notifications_total);
$ubermenu $templater->render();

$header str_replace('{ubermenu}'$ubermenu$header); 

Now, in your "header" template, put the string "{ubermenu}" wherever you want the rendering of "mytemplate" to appear. :)


All times are GMT. The time now is 07:22 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01144 seconds
  • Memory Usage 1,758KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (10)bbcode_code_printable
  • (1)bbcode_html_printable
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete