vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Problem with inserting a variable into a template (https://vborg.vbsupport.ru/showthread.php?t=284982)

Scanu 06-27-2012 08:39 PM

Problem with inserting a variable into a template
 
hello i have this code and works great but i have to add "{vb:raw login_panel}" to the header template
PHP Code:

$templater vB_Template::create('login_panel_html'); //Create html template
$login_panel $templater->render(); //saving template on a variable
$templater vB_Template::create('login_panel_css'); //Create css template
$login_panel_css $templater->render(); //saving template on a variable
$templater vB_Template::create('login_panel_javascript'); // Create javascript template
$login_panel_javascript $templater->render(); //saving template on a variable
$login_panel $login_panel.$login_panel_css.$login_panel_javascript//save templates variables on one var
vB_Template::preRegister('header',array('login_panel' => $login_panel)); //registering the variable variable 

What i'm trying to do is to put login_panel var on the header template without have to manually add it, so i tried this codes but it doesn't works
PHP Code:

$templater vB_Template::create('login_panel_html'); //Create html template
$login_panel $templater->render(); //saving template on a variable
$templater vB_Template::create('login_panel_css'); //Create css template
$login_panel_css $templater->render(); //saving template on a variable
$templater vB_Template::create('login_panel_javascript'); // Create javascript template
$login_panel_javascript $templater->render(); //saving template on a variable
$login_panel $login_panel.$login_panel_css.$login_panel_javascript//save templates variables on one var
$vbulletin->templatecache['header'] .= $login_panel//Adding templates var on the header 

It says "Parse error: syntax error, unexpected $end in /includes/class_core.php(4633) : eval()'d code on line 69"
someone that could help me? Or has another way to do it?

kh99 06-27-2012 09:26 PM

I think the problem is that the template cache contains php code, and you're tacking on html and css, which doesn't run as php code of course. Try this:


PHP Code:

$vbulletin->templatecache['header'] .= ' $final_rendered .= \'' addcslashes($login_panel.$login_panel_css.$login_panel_javascript"'\\") . '\'; '


Scanu 06-28-2012 07:01 AM

It works great but now i'm trying to add it to the begin of the template
I tred this but doesn't work
PHP Code:

$test ' $final_rendered .= \'' addcslashes($login_panel"'\\") . '\'; ';
$vbulletin->templatecache['header'] = $test.$vbulletin->templatecache['header']; 

Thanks for your great support :)

kh99 06-28-2012 11:03 AM

You can look at the compiled template in the database: the problem is that it starts like this:

Code:

$final_rendered = '<div class="above_body">

So that wipes out anything you add to the $final_rendered variable before that. So try this instead:

Code:

$replace = '$final_rendered = \'' . addcslashes($login_panel.$login_panel_css.$login_panel_javascript, "'\\") . '\' . '; 
$vbulletin->templatecache['header'] = substr_replace($vbulletin->templatecache['header'], $replace, 0, 17);


Scanu 06-28-2012 11:23 AM

works great thanks :)


All times are GMT. The time now is 09:20 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.01231 seconds
  • Memory Usage 1,738KB
  • 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
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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