vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Create and parse new templates (https://vborg.vbsupport.ru/showthread.php?t=154295)

Pod 08-04-2007 01:17 PM

Create and parse new templates
 
I'm trying to add a new template to my layout. The help says "When adding custom templates, in order to have them parsed, you must also write PHP code to call them." How I do that? And how I use my new template in another one?

nico_swd 08-04-2007 10:55 PM

Have a look at this article.

https://vborg.vbsupport.ru/showthread.php?t=62164

Pod 08-05-2007 12:00 AM

Thank you very much for your answer, nico_swd, but this is not what I need to do (in fact, I knew that article ;)). What I need to do is to use a custom template inside other (standard) ones. For instance, you see in the example provided in that article that they include the contents of the header template just by including the $header variable. That's what I need to do, create a new template (for instance, my_template) that I can include in other templates simply by writting the variable $my_template.

I assume, I need to write a plug-in in some place to process the contents of the template and store them in that variable?

EnIgMa1234 08-05-2007 12:06 AM

Your first need to cache the template then parse it.

The plugin hooks are called:

cache_templates
parse_templates

Pod 08-05-2007 12:21 AM

Quote:

Originally Posted by EnIgMa1234 (Post 1310037)
Your first need to cache the template then parse it.

The plugin hooks are called:

cache_templates
parse_templates

Thank you very much Enigma. This is very useful, thank you again.

Could you, please, point me where I can find an example of those plugins implemented? Lots of thanks in advance.

EnIgMa1234 08-05-2007 12:48 AM

In cache templates
Code:

               
                        $globaltemplates = array_merge($globaltemplates, array('YOURTEMPLATE'));

In parse templates
Code:

eval('$YOURVARIABLE = "' . fetch_template('YOURTEMPLATE') . '";');
Then you can use $YOURVARIABLE

Eikinskjaldi 08-05-2007 12:53 AM

When including one template in another what you actually do is eval the inner tamplate to a variable and then pass that variable to the outer template.

So for instance say you had a really simple innerTemplate that wraps <tr> tags around a series of entries


you might have this code
PHP Code:

foreach ($foo as $bar)
      eval(
'$innerBit .= "'.fetch_template('tr_wrap_bit').'";'); 

where the tr_wrap_bit sees the $bar variable.


Now you have a string ($innerBit) which contains a concatenation of the innerTemplate. You can simply then pass this variable to the next layer of template.

Pod 08-05-2007 01:18 AM

Thank you lots, Eikinskjaldi and Enigma. All this information has helped me a lot, and I've been able to complete my litlle project. I owe you both a free drink ;)

BTW, just saw at the main page od the forums... Happy birthday Enimga!!! Now I owe you two drinks :p


All times are GMT. The time now is 06:56 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.02210 seconds
  • Memory Usage 1,725KB
  • 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
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)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