Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-23-2016, 05:54 PM
Hilary Hilary is offline
 
Join Date: Jun 2002
Posts: 46
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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?
Reply With Quote
  #2  
Old 04-23-2016, 05:57 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #3  
Old 04-23-2016, 07:24 PM
Hilary Hilary is offline
 
Join Date: Jun 2002
Posts: 46
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.

Help?
Reply With Quote
  #4  
Old 04-24-2016, 02:04 AM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 04-24-2016, 06:54 AM
Hilary Hilary is offline
 
Join Date: Jun 2002
Posts: 46
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 . 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.
Reply With Quote
  #6  
Old 04-24-2016, 10:04 AM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What hook location are you using for your plugin?
Reply With Quote
  #7  
Old 04-24-2016, 10:18 AM
Hilary Hilary is offline
 
Join Date: Jun 2002
Posts: 46
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

parse_templates

(I tried 'global_start' first, but the template didn't appear at all.)
Reply With Quote
  #8  
Old 04-24-2016, 10:22 AM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try "global_setup_complete"...
Reply With Quote
  #9  
Old 04-24-2016, 10:33 AM
Hilary Hilary is offline
 
Join Date: Jun 2002
Posts: 46
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nope - template disappears altogether again.
Reply With Quote
  #10  
Old 04-24-2016, 06:45 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Благодарность от:
Lynne
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:28 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04765 seconds
  • Memory Usage 2,280KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (10)bbcode_code
  • (1)bbcode_html
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete