Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-08-2011, 01:44 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 07-08-2011, 01:58 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

<a href="https://vborg.vbsupport.ru/showthread.php?t=228078" target="_blank">https://vborg.vbsupport.ru/showthread.php?t=228078</a>
Reply With Quote
  #3  
Old 07-08-2011, 02:20 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
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.
Reply With Quote
  #4  
Old 07-08-2011, 02:25 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:reRegister() (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(); 
Reply With Quote
  #5  
Old 07-08-2011, 02:59 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #6  
Old 07-08-2011, 03:11 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 07-08-2011, 03:28 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #8  
Old 07-08-2011, 03:41 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 07-08-2011, 03:57 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:38 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04465 seconds
  • Memory Usage 2,271KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (1)bbcode_html
  • (5)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete