vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   vb4 custom template problem (https://vborg.vbsupport.ru/showthread.php?t=308030)

vsforums 02-07-2014 02:15 PM

vb4 custom template problem
 
Hi,

I want to use misc.php file to display my custom template.
Example:
misc.php?do=page&template=my_template

And everything works fine except that I cannot find a way to eval my own variable which is inside that template = {vb:raw HTML}

All other vars such as {vb:raw header} and {vb:raw footer} looks okay.

I tried to use parse_template hook to do something like:
global $HTML;

$HTML = "test";

But still HTML is null.

Any idea?

cellarius 02-07-2014 02:22 PM

Quote:

Originally Posted by vsforums (Post 2479569)
$global HTML;

That's not valid PHP.

Anyway, like for any other template, you need to properly register your variables for use in the template. I did an article on that: https://vborg.vbsupport.ru/showthread.php?t=228078

vsforums 02-07-2014 02:39 PM

I shouldn't have to do it. All that is in misc.php file. One thing that it is missing, is how to eval vars in custom templates. I'm sure there must be a way to do it.

kh99 02-07-2014 02:50 PM

Well, the misc.php code creates the template, registers some standard variables to it, then renders it, but if you're trying to use other variables then you need to deal with that. You could try using {vb:raw GLOBALS.HTML}, but if that doesn't work you could use vB_Template::preRegister() where $HTML is created, like:

PHP Code:

$HTML "test";
vB_Template::preRegsiter('my_template', array('HTML' => $HTML)); 


cellarius 02-07-2014 02:57 PM

Quote:

Originally Posted by vsforums (Post 2479575)
I shouldn't have to do it. All that is in misc.php file. One thing that it is missing, is how to eval vars in custom templates. I'm sure there must be a way to do it.

And exactly that way is described in my article. *shrug*

vsforums 02-07-2014 04:12 PM

Quote:

Originally Posted by cellarius (Post 2479581)
And exactly that way is described in my article. *shrug*

I didn't see anything about GLOBALS in your article and that is what worked here :)

Thx guys for help.

cellarius 02-07-2014 04:52 PM

Making a dirty global trick is not a solution, but a workaround. Of course, I thought you were looking for the correct way to do it in vB. Clearly my mistake, sorry.

kh99 02-07-2014 05:15 PM

Quote:

Originally Posted by cellarius (Post 2479603)
Making a dirty global trick is not a solution, but a workaround. Of course, I thought you were looking for the correct way to do it in vB. Clearly my mistake, sorry.

Yes, you have a point. I don't see any real problem with using GLOBALS that way for something "quick and dirty", but it's probably a good idea to point out that it's not the intended way of doing things, and if you're doing any substantial amount of coding with templates you would want to learn how to register variables. And a good way to do that is to study the article mentioned above.

cellarius 02-07-2014 06:04 PM

BTW, quick and dirty is what I meant above - dirty alone does not catch it. Sorry, english is not my mother tongue ;)

vsforums 02-07-2014 07:23 PM

Quote:

Originally Posted by cellarius (Post 2479603)
Making a dirty global trick is not a solution, but a workaround. Of course, I thought you were looking for the correct way to do it in vB. Clearly my mistake, sorry.

You are right. I've reviewed and tested both options and I went with preRegister one ;)

Thx again.


All times are GMT. The time now is 04:59 PM.

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.00996 seconds
  • Memory Usage 1,736KB
  • 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_php_printable
  • (5)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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