vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   How Can I use a custom template as a variable (https://vborg.vbsupport.ru/showthread.php?t=266472)

EquinoxWorld 07-08-2011 01:44 PM

How Can I use a custom template as a variable
 
Hello everyone, does anyone know how I can use a custom template (for example: COFTW_FAQ) and insert it as a variable into another template (OFTW). I saw this article here https://vborg.vbsupport.ru/showthread.php?t=119933 but it's not working for me with vb4. Anyone know where I can find updated documentation on this? Basically I want to use a custom template inside another template using a plug in. Any ideas anyone? Please help. :)

kh99 07-08-2011 01:58 PM

<a href="https://vborg.vbsupport.ru/showthread.php?t=228078" target="_blank">https://vborg.vbsupport.ru/showthread.php?t=228078</a>

EquinoxWorld 07-08-2011 02:20 PM

Quote:

Originally Posted by kh99 (Post 2218152)

Thank you for the link. Although I see that I can register a variable and use it in a template, that's fine but how do I register a template as a variable then use it in another template? I'm so lost right now, any help will be so much appreciated.

Basically I want to crate a "shell" and then use {vb:raw oftw_faq} (which is the contents of another custom template) inside that template.

kh99 07-08-2011 02:25 PM

Scroll down to the section that's labeled "Save into a variable for later use in custom template". Basically you save the output of render() into a variable, then you use it in another template like you would any other variable. If the "including" template is also one you're rendering in your code, then you can just register the variable as you would any other. If you want to include it in one of the existing vb templates, then you probably need to use vB_Template::preRegister() (search for that in the article linked above).

Using examples from the article,

PHP Code:

$templater vB_Template::create('mytemplate1');
    
$templater->register('my_var'$my_var);
    
$templater->register('my_array'$my_array);
$mytemplate_rendered $templater->render();
...
$templater vB_Template::create('mytemplate2');
    
$templater->register('my_template1'$mytemplate_rendered);
    
$templater->register('my_array2'$my_array2);
$mytemplate2_rendered $templater->render(); 


EquinoxWorld 07-08-2011 02:59 PM

So it would be 2 plug-ins that I wold have to create right? One to render the template as a variable then another to render the variable in the other template?

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

OK this is what I got so far:
First Plug-in to register the template into a variable:
PHP Code:

$templater vB_Template::create('COFTW_FAQ'); 
    
$templater->register('oftw_faq'$oftw_faq); 
$mytemplate_rendered $templater->render(); 

Second Plug-in to register my variable into the "shell" template:

PHP Code:

$templater vB_Template::create('OFTW'); 
    
$templater->register('COFTW_FAQ'$mytemplate_rendered); 
$mytemplate2_rendered $templater->render(); 

And I'm using:
Code:

{vb:raw oftw_faq}
in the OFTW template but it does not show up still. ANy ideas what I could be doing wrong?

kh99 07-08-2011 03:11 PM

It could be two plugins or the same plugin, it just depends on what you're doing (if you're using the same hook location for both, then you definitely don't need two plugins).

Based on the code you posted, you'd need {vb:raw oftw_faq} in the 'COFTW_FAQ' template to see $oftw_faq, and {vb:raw COFTW_FAQ} in the 'OFTW' template to see the first template.

Also if you use two plugins, depending on the hook locations, you might need "global $mytemplate2_rendered;" in one or both locations.

BTW, you're missing a couple of quotes in the code for the second template.

EquinoxWorld 07-08-2011 03:28 PM

Basically I want to create a "shell" template with OFTW. With OFTW being the main template and using COFTW_FAQ template as an insert into OFTW. The script that uses OFTW is oftw.php and I just created template COFTW_FAQ with the following contents which I want to insert into OFTW:

HTML Code:

<div class=block>
            <h2 class=blockhead>F.A.Q</h2>
                <div class=blockbody>Hello
                    </div>
</div>

Does that mean I have to include the second template in oftw.php?

Updated Plug-ins: (still not working :( ) (both with global_start as hook)

PHP Code:

$templater vB_Template::create('COFTW_FAQ'); 
    
$templater->register('oftw_faq'$oftw_faq); 
$mytemplate_rendered $templater->render(); 

PHP Code:

$templater vB_Template::create('OFTW'); 
    
$templater->register('COFTW_FAQ'$mytemplate_rendered); 
$mytemplate2_rendered $templater->render(); 

And using {vb:raw COFTW_FAQ} in OFTW template but still not getting anything. Any more ideas as to why still not showing up anything?

kh99 07-08-2011 03:41 PM

If you're using the same hook location then you should probably just use one plugin. But if you want to use two for whatever reason, then you should set the execution order fields so that they run in the order you expect.

But if you've created a php file called oftw.php, then you may not need to use plugins at all, just put the code you need in the file. There's nothing magic about a plugin, it just lets you add code without editing the existing php files.

EquinoxWorld 07-08-2011 03:57 PM

Quote:

Originally Posted by kh99 (Post 2218200)
If you're using the same hook location then you should probably just use one plugin. But if you want to use two for whatever reason, then you should set the execution order fields so that they run in the order you expect.

But if you've created a php file called oftw.php, then you may not need to use plugins at all, just put the code you need in the file. There's nothing magic about a plugin, it just lets you add code without editing the existing php files.

True although for what I am trying to accomplish it is better. I am trying to use javascript to load diferent content (within the OFTW template) inside a div. using this code for example:

Code:

<li class="usercp_nav"><a href="JavaScript:void()" onclick="document.getElementById('DivExample').innerHTML = '<p>{vb:raw COFTW_FAQ}</p>';">F.A.Q</a></li>
So I can create a side menu and when clicking on one of the menu links the content on the right changes so I wanted to use plug ins so I won't have to write the entire code instead of just {vb:raw COFTW_FAQ}. This would make it easier to edit the content of each menu item. I know I can just have the content load non a different page but I am trying to have ti inline with JavaScript.


All times are GMT. The time now is 04:59 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.01085 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
  • (2)bbcode_code_printable
  • (1)bbcode_html_printable
  • (5)bbcode_php_printable
  • (2)bbcode_quote_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