vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Design and Graphics Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=253)
-   -   Call a custom template in various places (https://vborg.vbsupport.ru/showthread.php?t=319580)

Scimia 07-21-2015 11:58 AM

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?

kh99 07-21-2015 01:15 PM

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

Scimia 07-21-2015 02:28 PM

Quote:

Originally Posted by kh99 (Post 2550936)
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()); 


kh99 07-21-2015 02:43 PM

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.

Scimia 07-21-2015 04:06 PM

Quote:

Originally Posted by kh99 (Post 2550945)
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.

kh99 07-21-2015 04:23 PM

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

PHP Code:

    $templater->register('post'$userinfo); 


kh99 07-21-2015 04:29 PM

Oh, if you're putting it in a block you probably need a different hook. Maybe try 'member_execute_start' instead.


All times are GMT. The time now is 04:49 PM.

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.01187 seconds
  • Memory Usage 1,754KB
  • 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
  • (2)bbcode_code_printable
  • (4)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete