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

Reply
 
Thread Tools Display Modes
  #1  
Old 05-19-2014, 08:36 PM
omardealo's Avatar
omardealo omardealo is offline
 
Join Date: Nov 2008
Location: egypt
Posts: 235
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default how i can add custom template on sidebar-block

Hello ,

i try to add a custom template on sidebar-block , but don't show anything

PHP-BLOCK:

PHP Code:
$template vB_Template::create("my template name");
$my_output $template->render();
return 
$my_output
Note: The template contains Some variables, for my mod 4.4.2
and i used {vb:raw ad_location.var} for show my template on anywhere on forum templats but not works on sidebar - Html Block.
Thank you !
Reply With Quote
  #2  
Old 05-19-2014, 09:30 PM
Lionel Lionel is offline
 
Join Date: Dec 2001
Location: Delray Beach, Florida
Posts: 3,277
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

if you want to see it right away make sure you set the cache time to 0
Reply With Quote
  #3  
Old 05-19-2014, 10:02 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You need to register the variables for use in the template. Cellarius wrote a really good article that you may be interested in - [vB4] Rendering templates and registering variables - a short guide
Reply With Quote
Благодарность от:
omardealo
  #4  
Old 05-19-2014, 10:17 PM
omardealo's Avatar
omardealo omardealo is offline
 
Join Date: Nov 2008
Location: egypt
Posts: 235
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
You need to register the variables for use in the template. Cellarius wrote a really good article that you may be interested in - [vB4] Rendering templates and registering variables - a short guide
i already do that , register all variables i used it on my template ..
PHP Code:
$templater vB_Template::create('my template name');  
$templater->register('var'$var);  
$something $templater->render();  
$ad_location['something'] = $templater->render(); 
i said befor , every thing is okay ... and i can print my temp on any another template (footer,header,elc...) by :
PHP Code:
{vb:raw ad_location.something 
but i want print it on sidebar ... that's only my problem
Thank you !
Reply With Quote
  #5  
Old 05-20-2014, 11:16 AM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
// Three templates were created.  
//  1. block_custom - Custom block php/html template  
//      (Cloned from "block_html" template with added <vb raw variables> listed below).
//  2. my_template name - to be inserted in "block_custom"
//  3. ad_template - to be inserted in "block_custom"


// Outputs to "block_custom"  <vb: raw content>,  as inserted custom template
vB_Template::create('my template name');  
$templater->register('var1'$var1);   // Other template variables 
$templater->register('var2'$var2);   //    results outputted from PHP.
$output $templater->render();  

// Output "ad_template" --- outputs to "block_custom"  <vb:raw ad_location>
$templater vB_Template::create('ad_template');  
$templatevalues['ad_location'] = $templater->render();
vB_Template::preRegister('block_custom'$templatevalues); 
This is probably not exactly what you are looking for, but you can derive it from this.
This was modeled after the page @Lynne referred you to, it is revised for forum blocks.
Reply With Quote
2 благодарности(ей) от:
Lynne, omardealo
  #6  
Old 05-20-2014, 11:08 PM
omardealo's Avatar
omardealo omardealo is offline
 
Join Date: Nov 2008
Location: egypt
Posts: 235
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by tbworld View Post
PHP Code:
// Three templates were created.  
//  1. block_custom - Custom block php/html template  
//      (Cloned from "block_html" template with added <vb raw variables> listed below).
//  2. my_template name - to be inserted in "block_custom"
//  3. ad_template - to be inserted in "block_custom"


// Outputs to "block_custom"  <vb: raw content>,  as inserted custom template
vB_Template::create('my template name');  
$templater->register('var1'$var1);   // Other template variables 
$templater->register('var2'$var2);   //    results outputted from PHP.
$output $templater->render();  

// Output "ad_template" --- outputs to "block_custom"  <vb:raw ad_location>
$templater vB_Template::create('ad_template');  
$templatevalues['ad_location'] = $templater->render();
vB_Template::preRegister('block_custom'$templatevalues); 
This is probably not exactly what you are looking for, but you can derive it from this.
This was modeled after the page @Lynne referred you to, it is revised for forum blocks.

Thanks, but i did not understand very well this way
I do created three templates ? Then what? How will the template show inside the block?
I reviewed the solutions here
https://vborg.vbsupport.ru/showthread.php?t=293516
But it did not work with me becouse he put all php code inside block , but iam Use plugin .

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

when i put anything without variables , it Show inside block
so , this code is work good ,
PHP Code:
$templater vB_Template::create('my_template'); 
return 
$templater->render(); 
but problem now that variables do not work in the block ؟!
Reply With Quote
  #7  
Old 05-21-2014, 05:40 AM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PM me your plugin code, forum_block code, and block templates. I will take a look at it.
You are talking about just adding an 'Ad' via a plugin to a custom "forum block", correct?

The array ($ad_locator) is already registered to all templates that use the templater. Therefore, if you write a plugin to hook "parse_templates" the "$ad_locator" array variable will already be passed to the template (does not need to be registered). The same is true if you are passing a template to that same variable. To reiterate there are several global variables that are automatically registered to the template system, "ad_locator" is one of them.

For Example: if I create the template variable {vb:raw ad_location.tbworld_ad_template_hook_variable} in my custom "forumblock" template, then the following plugin code will display my custom 'AD' template inside my custom "forumblock" template;

Plugin:
PHP Code:
// HOOK: parse_templates
$ad_location['tbworld_ad_template_hook_variable'] = vB_Template::create('ad_global_below_navbar')->render(); 

Custom Forum Block Template: "block_tbworld"
HTML Code:
<!-- block_tbworld - START -->
<!-- Custom "forum_block" template -->

<li>
    <div class="block smaller">
        <div class="blocksubhead">
            <a class="collapse">  <!-- collapse code chopped -->
            <span class="blocktitle">{vb:raw blockinfo.title}</span>
        </div>
        <div class="widget_content blockbody floatcontainer">
            <div id="block_tbworld_{vb:raw blockinfo.blockid}" class="blockrow">

                <!-- This is where the forum block "$output" is sent -->
                <!-- This can be another template or HTML code. -->
                {vb:raw content}

                <!-- Template Variable: for custom "AD" template or custom "AD" HTML code -->
                {vb:raw ad_location.tbworld_ad_template_hook_variable}
            </div>
        </div>
    </div>
    <div class="underblock"></div>
</li>
<!-- block_tbworld - END -->
Reply With Quote
  #8  
Old 05-21-2014, 07:58 AM
omardealo's Avatar
omardealo omardealo is offline
 
Join Date: Nov 2008
Location: egypt
Posts: 235
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Exactly , that's what i want .. yeah
i sent to you my code on PM , becouse i try this way but not work with me ..
thnx bro ,
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 12:52 AM.


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.04234 seconds
  • Memory Usage 2,272KB
  • 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
  • (1)bbcode_html
  • (7)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (3)post_thanks_box_bit
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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_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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete