vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Rendering Custom Template (https://vborg.vbsupport.ru/showthread.php?t=229281)

Seven Skins 12-01-2009 08:20 PM

Rendering Custom Template
 
I have tried following this: https://vborg.vbsupport.ru/showthread.php?t=228078 but no luck with what I am trying to do.
Most probably it will be simple solution but I can not get it to work. (I am new to writing plugins etc ...)

What I am trying to do is:

I have template name "TEST" with just simple HTML code <div>Some text</div>

And I just want this HTML to be inserted into e.g. footer template.

I have tried this in global_start plugin.

PHP Code:

$templater vB_Template::create('TEST');
$test $templater ->render();
vB_Template::preRegister('footer',array('test' => $test)); 

or

PHP Code:

$templater vB_Template::create('TEST');
$templatevalues['test'] = $templater->render();
vB_Template::preRegister('footer'$test); 

And this in footer template.

PHP Code:

{vb:raw test


But that template does not show in footer template.


Thanks

.

Lynne 12-01-2009 08:33 PM

If you are creating a whole different footer template, then I would call it something else. The footer template gets rendering by the vbulletin engine very early on, and if you are using the same name, then you may get weird results.

Seven Skins 12-01-2009 08:47 PM

No, I just want to add something to footer template ... but need separate template for it, as this template will be edited frequently. I am working on a simple product which I will release here if successful :)

.

Lynne 12-01-2009 08:57 PM

Ah, now I see what you are doing. I wasn't reading it correctly. The first code that you posted looks correct. However, what hook location are you using? As I said before, the footer template gets rendered at the very beginning (in the global.php file) and you may to render it again in order to get your stuff added.

Lynne 12-01-2009 09:07 PM

Ah, now I see what you are doing. I wasn't reading it correctly. The first code that you posted looks correct. However, what hook location are you using? As I said before, the footer template gets rendered at the very beginning (in the global.php file) and you may to render it again in order to get your stuff added.

Seven Skins 12-01-2009 09:17 PM

I have used global_start hook location.

This seems to add the data to footer with the above hook.

PHP Code:

$test "Some text here";
vB_Template::preRegister('footer',array('test' => $test)); 

But I need to add/render the template.

.

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

I have searched "class_bootstrap.php" and found that "parse_templates" was called just before header and footer templates got rendered.

"parse_templates" hook seems to work.

.

Lynne 12-01-2009 09:58 PM

So let's see the code you are trying to use to render the template and then preregister it. And, look up where the footer template is rendered... the parse_templates hook is right above there. Have you tried it?

Seven Skins 12-01-2009 10:04 PM

Yup, its working (As replied above) :)

Here is the code I used in "parse_templates" hook:

PHP Code:

$templater vB_Template::create('TEST');
$templatevalues['test'] = $templater->render();
vB_Template::preRegister('footer'$templatevalues);
vB_Template::preRegister('header'$templatevalues); 

And this in footer or/and header template:
PHP Code:

{vb:raw test


Thanks

.

RagingPenguin 04-27-2011 04:02 PM

How would one go about doing this in a way that would make a custom template available in all other templates, and not have to preRegister each of them?

Here's what I have so far.

cache_templates
PHP Code:

$cache array_merge($cache, array(
'layout_a',
'layout_b',
'layout_c',
'layout_d'
)); 

parse_templates
PHP Code:

global $layout_a$layout_b$layout_c$layout_d;
$layout_a vB_Template::create('layout_a')->render();
$layout_b vB_Template::create('layout_b')->render();
$layout_c vB_Template::create('layout_c')->render();
$layout_d vB_Template::create('layout_d')->render();


But I think it should be more like:

parse_templates
PHP Code:

global $layout_a$layout_b$layout_c$layout_d;
$layout_a vB_Template::create('layout_a')->render();
$layout_b vB_Template::create('layout_b')->render();
$layout_c vB_Template::create('layout_c')->render();
$layout_d vB_Template::create('layout_d')->render();

// for each cached template, global or otherwise, register
// the above templates as variables
foreach ($globaltemplates as $key => $value)
{
vB_Template::preRegister($key, array(
'layout_a' => $layout_a,
'layout_b' => $layout_b,
'layout_c' => $layout_c,
'layout_d' => $layout_d
)); 

I know it doesn't work, but that's because I'm not sure what array to use/globalize here.

Help?


All times are GMT. The time now is 07:11 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.01896 seconds
  • Memory Usage 1,757KB
  • 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
  • (9)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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