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

Reply
 
Thread Tools Display Modes
  #1  
Old 07-21-2015, 11:58 AM
Scimia Scimia is offline
 
Join Date: Aug 2011
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Call a custom template in various places

I have this code

PHP Code:
            <vb:if condition="is_member_of($post, 6, 69)">
                <
div class="targhetta admin"><span class="orecchie"></span><span class="text">Amministratore</span></div>
                <
br style="content: ' '; display: block; margin-top: 5px;" />
            </
vb:if>
            <
vb:if condition="is_member_of($post, 5)">
                <
div class="targhetta smod"><span class="orecchie"></span><span class="text">Supermoderatore</span></div>
                <
br style="content: ' '; display: block; margin-top: 5px;" />
            </
vb:if>
            <
vb:if condition="is_member_of($post, 7)">
                <
div class="targhetta mod"><span class="orecchie"></span><span class="text">Moderatore</span></div>
                <
br style="content: ' '; display: block; margin-top: 5px;" />
            </
vb:if> 
I want to create a custom template and call it in postbit_legacy and memberinfo, how can I do this?
Reply With Quote
  #2  
Old 07-21-2015, 01:15 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You would need to use a plugin. In the plugin you'd set up any variables you need, register them to your template, then render the template and save the output in a variable. You'd then register that variable to the postbit template, and then use 'vb:raw' in postbit to put it where you want.

I know that sounds complicated, but it's not really that difficult. There's an article here on how to render a template: https://vborg.vbsupport.ru/showthread.php?t=228078
Reply With Quote
Благодарность от:
MarkFL
  #3  
Old 07-21-2015, 02:28 PM
Scimia Scimia is offline
 
Join Date: Aug 2011
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
You would need to use a plugin. In the plugin you'd set up any variables you need, register them to your template, then render the template and save the output in a variable. You'd then register that variable to the postbit template, and then use 'vb:raw' in postbit to put it where you want.

I know that sounds complicated, but it's not really that difficult. There's an article here on how to render a template: https://vborg.vbsupport.ru/showthread.php?t=228078
Appears a bit complicated also in the article, can't you write me some specific example for my problem?

For example, I have a custom template called "targhette" (that contains the code I've posted above) and i want to call it with {vb:raw targhette} in postbit_legacy and memberinfo, how I can do this?

I need to create a new plugin with this code? Is this correct?

PHP Code:
$templater vB_Template::create('targhette');
    
$templater->register_page_templates(); 
    
$templater->register('my_var'$my_var);
    
$templater->register('my_array'$my_array);
print_output($templater->render()); 
Reply With Quote
  #4  
Old 07-21-2015, 02:43 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That's pretty close. I think like this:

Code:
$templater = vB_Template::create('targhette');
    $templater->register_page_templates(); 
    $templater->register('my_var', $my_var);
    $templater->register('my_array', $my_array);
$targhette = $templater->render();  

vB_Template::preRegister('postbit_legacy', array('targhette' => $targhette));
and using hook postbit_display_complete, probably. For memberinfo you'd need another plugin (and change the template name in preRegister, of course). For that one use hook member_complete instead. Also, there is no $post for the memberinfo, but the user's info is in $userinfo, so you could just put $userinfo in place of $post in the register call. If you leave the name in the register call as 'post' then you can use the same template.

Edit: oh, I'm assuming that you know that the my_var and my_array register lines are just examples. If you use variables in your custom template, you'd want to replace those two lines with one or more lines to register your variables.
Reply With Quote
  #5  
Old 07-21-2015, 04:06 PM
Scimia Scimia is offline
 
Join Date: Aug 2011
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
That's pretty close. I think like this:

Code:
$templater = vB_Template::create('targhette');
    $templater->register_page_templates(); 
    $templater->register('my_var', $my_var);
    $templater->register('my_array', $my_array);
$targhette = $templater->render();  

vB_Template::preRegister('postbit_legacy', array('targhette' => $targhette));
and using hook postbit_display_complete, probably. For memberinfo you'd need another plugin (and change the template name in preRegister, of course). For that one use hook member_complete instead. Also, there is no $post for the memberinfo, but the user's info is in $userinfo, so you could just put $userinfo in place of $post in the register call. If you leave the name in the register call as 'post' then you can use the same template.

Edit: oh, I'm assuming that you know that the my_var and my_array register lines are just examples. If you use variables in your custom template, you'd want to replace those two lines with one or more lines to register your variables.
I've got this working for the postbit, but now i'm having problem to get this work in user profile, I need to use the same template (targhette) but in this page.

I'm trying with this plugin:

PHP Code:
$templater vB_Template::create('targhette');
    
$templater->register_page_templates(); 
    
$templater->register('userinfo'$post);
$targhette $templater->render();  

vB_Template::preRegister('memberinfo_block_ministats', array('targhette' => $targhette)); 
And I write {vb:raw targhette} in memberinfo_block_ministats, but doesn't work.
The template hook i'm using is member_complete.
Reply With Quote
  #6  
Old 07-21-2015, 04:23 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think you want to change the userinfo register line like this:

PHP Code:
    $templater->register('post'$userinfo); 
Reply With Quote
  #7  
Old 07-21-2015, 04:29 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh, if you're putting it in a block you probably need a different hook. Maybe try 'member_execute_start' instead.
Reply With Quote
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 07:07 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.14002 seconds
  • Memory Usage 2,249KB
  • Queries Executed 13 (?)
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
  • (2)bbcode_code
  • (4)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (1)post_thanks_box_bit
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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_postinfo_query
  • fetch_postinfo
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete