vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=242)
-   -   [HOW TO - vB4] Rendering templates and registering variables - a short guide (https://vborg.vbsupport.ru/showthread.php?t=228078)

CypherSTL 12-28-2009 05:46 PM

I still cannot figure out how in the heck to work this new template system.

Code:

eval('$awarduserslist .= ", ' . fetch_template('awards_awardusers_bit') . '";');
Works flawlessly. No errors.

However
Code:

$displayTemplate = vB_Template::create('awards_awardusers_bit');
$awarduserslist .= $displayTemplate->render();

Displays absolutely NOTHING.

scarex 12-29-2009 10:46 AM

Thanks for this guide, at the beginning I was totally confused about this new system.

On the other hand, is there a system to preregister a var in all templates with a single call?

IR15H 12-29-2009 11:51 PM

Thanks for the guide :)

rbc 12-31-2009 12:52 PM

Quote:

Originally Posted by cellarius (Post 1915072)
Introduction
~snip~

@ cellarius

Absolutly a great introduction how things now working on VB4.
It answere`s many questions to me now.

I just wanne thank you cellarius for this.

btw. many thanks to Lynne who also allways help out.

i`m absolutly new to stuff like "vb" or "php" but with your "helping
hand`s" alot of work is possible to do for me too.

Sorry about my englisch, its not "my one" :)

Thanks again an enjoy the hollydays ...... if there some ........

NLP-er 01-06-2010 12:32 AM

I have question:
How to change content of existing template inside of plugin?

I'm remaking my mod for vB4. I'm adding there flags to header of footer. In vB3 version I simply change insides of template using templatecache. I.e.:
PHP Code:

$vbulletin->templatecache['footer'] .= 'ADDITIONAL TEXT IN FOOTER'

I was using it in global_start hook, but it doesn't work anymore - $vbulletin->templatecache['footer'] is empty and have no impact on footer.

How to change this line of code to make it working in vB4?

EDIT:
Ok - I already found it here :) Now check if its working :P

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

Other question:
In vB3 my mod have possibility to put additional data in custom place - so user just manually adds variable into required template and he has flags where he put it. How to do this in vB4 where variables have to be preregistered????...

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

Quote:

Originally Posted by testebr (Post 1916821)
I figure out how to solve it:

hook: process_templates_complete

code: $footer .= 'text added to footer';

No idea if was the best solution, but that worked very well.

This will work only for few templates. The question is how to make it work for any template like with $vbulletin->templatecache solution in vB3.

Also this solution is working on already parsed template - I need fresh one, not parsed yet. Anyone have idea how to do that?

EDIT
Ok I have it :) need to use hook parse_templates

Sarcoth 01-07-2010 05:22 PM

Awesome guide. It has helped me move forward a bit, but I still don't have it all down yet. If anyone has this down pat, I'd be interested in some more tutorials that show old 3.x code and then below shows the 4.x code. This way I can test myself and see how well I have it down.

In the meantime though, is the new rendering needed for redirects? For example:
Code:

$vbulletin->url = "misc.php?do=editform&fid=$fid";
eval(print_standard_redirect('redirect_insertform', true));

I tried the following:
Code:

$templater = vB_Template::create('redirect_insertform');
        $templater->register_page_templates();
        $templater->register('redirect', $vbulletin->url);
print_standard_redirect($templater->render());

That didn't work though, it seems to be cutting off everything after misc.php. Maybe I need to register the $fid?

cellarius 01-07-2010 07:28 PM

No, standard redirects and errors still work the old way. If you want to know something like that, just look one up in the original vB4 php files.

Abe Babe 01-12-2010 06:26 AM

I have a template that I need to insert into multiple pre-existing templates (I add some additional graphics/formatting to the header and footer of most tables ... and my CSS skills aren't good enough to achieve what I'm trying to do through CSS alone, so I need to add old HTML table coding). I do it this way so that if I want to make changes, I don't have to change lots of different templates. After a bit of struggling, I have managed to get the following code running.

Code:

$templater = vB_Template::create('layout_start');
    $templater->register('my_var', $my_var);
$templatevalues['start_insertvar'] = $templater->render();
vB_Template::preRegister('FORUMHOME', $templatevalues);


I have two questions. Is there any way to preRegister for more than one pre-existing template (or a global registration), or do I have to create Plugins for every page I want to add this to (*groan*)? And what is the best hook to have this on. I am currently using 'parse_templates'.

The other unusual thing I'm finding happening is if I include my template in postbit_legacy, it will show on the first post, but not on the posts after that.

Thanks in advance...

cellarius 01-13-2010 01:16 AM

Quote:

Originally Posted by Abe Babe (Post 1953310)
Code:

$templater = vB_Template::create('layout_start');
    $templater->register('my_var', $my_var);
$templatevalues['start_insertvar'] = $templater->render();
vB_Template::preRegister('FORUMHOME', $templatevalues);

I have two questions. Is there any way to preRegister for more than one pre-existing template (or a global registration), or do I have to create Plugins for every page I want to add this to (*groan*)?

Just calling the preregister method as often as you need it might not work in this case, since the method clears the variable. So trying to simply preregister it again might not be feasible. Anyway, try this:
Code:

$templater = vB_Template::create('layout_start');
    $templater->register('my_var', $my_var);
$templatevalues['start_insertvar'] = $templater->render();
vB_Template::preRegister('FORUMHOME', $templatevalues);
vB_Template::preRegister('SHOWTHREAD', $templatevalues);
vB_Template::preRegister('FORUMDISPLAY', $templatevalues);

If this does not work, try something like this:
Code:

$templater = vB_Template::create('layout_start');
    $templater->register('my_var', $my_var);
$start_insertvar = $templater->render();
$templatevalues['start_insertvar'] = $start_insertvar;
vB_Template::preRegister('FORUMHOME', $templatevalues);
$templatevalues['start_insertvar'] = $start_insertvar;
vB_Template::preRegister('SHOWTHREAD', $templatevalues);
$templatevalues['start_insertvar'] = $start_insertvar;
vB_Template::preRegister('FORUMDISPLAY', $templatevalues);

Of course, if you have really many templates, it might be more elegant to solve this with an array an a nice loop.
Quote:

And what is the best hook to have this on. I am currently using 'parse_templates'.
Seems fine to me.

Ted S 01-16-2010 05:19 PM

...


All times are GMT. The time now is 11:18 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.03279 seconds
  • Memory Usage 1,755KB
  • 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
  • (8)bbcode_code_printable
  • (1)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (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