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

Reply
 
Thread Tools Display Modes
  #1  
Old 02-07-2014, 02:15 PM
vsforums vsforums is offline
 
Join Date: Aug 2006
Posts: 32
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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?
Reply With Quote
  #2  
Old 02-07-2014, 02:22 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by vsforums View Post
$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
Reply With Quote
  #3  
Old 02-07-2014, 02:39 PM
vsforums vsforums is offline
 
Join Date: Aug 2006
Posts: 32
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 02-07-2014, 02:50 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:reRegister() where $HTML is created, like:

PHP Code:
$HTML "test";
vB_Template::preRegsiter('my_template', array('HTML' => $HTML)); 
Reply With Quote
  #5  
Old 02-07-2014, 02:57 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by vsforums View Post
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*
Reply With Quote
  #6  
Old 02-07-2014, 04:12 PM
vsforums vsforums is offline
 
Join Date: Aug 2006
Posts: 32
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by cellarius View Post
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.
Reply With Quote
  #7  
Old 02-07-2014, 04:52 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #8  
Old 02-07-2014, 05:15 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by cellarius View Post
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.
Reply With Quote
  #9  
Old 02-07-2014, 06:04 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

BTW, quick and dirty is what I meant above - dirty alone does not catch it. Sorry, english is not my mother tongue
Reply With Quote
  #10  
Old 02-07-2014, 07:23 PM
vsforums vsforums is offline
 
Join Date: Aug 2006
Posts: 32
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by cellarius View Post
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.
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 09:55 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.04387 seconds
  • Memory Usage 2,249KB
  • Queries Executed 11 (?)
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_php
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete