vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Help creating a plug-in that puts code into a template (https://vborg.vbsupport.ru/showthread.php?t=283975)

skedarisetty 06-05-2012 11:47 AM

Help creating a plug-in that puts code into a template
 
For addition of some "div" content into footer template, I have modified the template. the code for it looks something like this.

<vb:if condition="!empty($threadinfo[threadid])">
<!-- add two scripts -->
<div>
Some html code
</div>
<script type="text/javascript" language="JavaScript">
callme("variable1" ,{vb:raw threadinfo.threadid});
</script>
</vb:if>

I registered $threadinfo in the footer template and it is working fine. But I want to package it into a plug-in and put the same code into the template using that plug-in. So I created a template with above code chunk.

I created a product and a plug-in in it: I created the plug-in for the hook "parse_templates"
My Plugin code looks like this.
$tpl = vB_Template::create('mytemplate');
$template_hook['footer_test_hook'] = htmlentities($tpl->render());

and I put {vb:raw template_hook.footer_test_hook} in the footer template.

But nothing seems to render in the thread page. I would really appreciate it if some one guides me to the right way.

kh99 06-05-2012 12:00 PM

I think you need to add a line to register threadinfo to your template, like:

Code:

$tpl = vB_Template::create('mytemplate');
$tpl->register('threadinfo', $threadinfo);
$template_hook['footer_test_hook'] = htmlentities($tpl->render());


And that will only work if $threadinfo is available at that hook, which I'm not sure of offhand (I guess if you had it working directly in the footer template, then it probably is).

Also, I don't think you need the call to htmlentities().


All times are GMT. The time now is 01:05 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.00909 seconds
  • Memory Usage 1,709KB
  • 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
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)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