PDA

View Full Version : how i can add custom template on sidebar-block


omardealo
05-19-2014, 08:36 PM
Hello ,

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

PHP-BLOCK:

$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 !

Lionel
05-19-2014, 09:30 PM
if you want to see it right away make sure you set the cache time to 0

Lynne
05-19-2014, 10:02 PM
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 (https://vborg.vbsupport.ru/showthread.php?t=228078)

omardealo
05-19-2014, 10:17 PM
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 (https://vborg.vbsupport.ru/showthread.php?t=228078)

i already do that , register all variables i used it on my template ..
$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 :
{vb:raw ad_location.something }
but i want print it on sidebar ... that's only my problem
Thank you !

tbworld
05-20-2014, 11:16 AM
// 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.

omardealo
05-20-2014, 11:08 PM
// 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 :cool: becouse he put all php code inside block , but iam Use plugin .

--------------- Added 1400632326 at 1400632326 ---------------

when i put anything without variables , it Show inside block
so , this code is work good ,

$templater = vB_Template::create('my_template');
return $templater->render();

but problem now that variables do not work in the block ؟!

tbworld
05-21-2014, 05:40 AM
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:

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



Custom Forum Block Template: "block_tbworld"

<!-- 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 -->

omardealo
05-21-2014, 07:58 AM
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 ,