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 05-31-2011, 01:40 AM
TWood's Avatar
TWood TWood is offline
 
Join Date: Mar 2009
Location: Washington DC
Posts: 96
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Pass a vBulletin variable to Javascript?

There is a vBulletin variable called {vb:raw criteriaDisplay} that can be called into a template just by naming it:

Code:
<p>{vb:raw criteriaDisplay}</p>
will show the current value. The current value is the Tag search term that is used to create the tag search results. (I edited out the "Tag:" part in the PHP file that creates it, so your Tag search result list may include that part.)

I need to access that variable within a Javascript on the same page that calls in ads based on its value. So far we haven't been able to pass the variable to Javascript simply by calling it. One of the comments at DevShed said:

Quote:
"... you probably won't be able to use {vb: raw criteriaDisplay} to determine the number that needs to go there. You need to have this number available before the template is rendered ..."
So, how can I make {vb: raw criteriaDisplay} available to a Javascript on the page, before the template is rendered?

Thanx
Reply With Quote
  #2  
Old 05-31-2011, 01:47 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't understand the quote in your post. If the number appears in the page then it's available before the template is rendered (unless you're talking about a different template?).

In any case, have you tried putting this in the template?

HTML Code:
<script type="text/javascript">
var criteriaDisplay = "{vb:raw criteriaDisplay}";
</script>
Reply With Quote
  #3  
Old 05-31-2011, 02:11 AM
TWood's Avatar
TWood TWood is offline
 
Join Date: Mar 2009
Location: Washington DC
Posts: 96
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks kh99 -

Adding that script yields this in View Source:

Code:
<script type="text/javascript">
var criteriaDisplay = "";
</script>
Which is the same problem in the main Javascript, it's just not seeing the variable. There should be a number there between the quotes that matches the number that is shown on the page where I have <p>{vb:raw criteriaDisplay}</p>. It calls the variable fine outside of Javascript.

Regarding the quote, yes it's the same page/template.
Reply With Quote
  #4  
Old 05-31-2011, 02:28 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm...that's strange - it works for me. I had this set up to test soimething else:

In a plugin at global_start
Code:
$criteriaDisplay = 5;
vB_Template::preRegister('header',array('criteriaDisplay' => $criteriaDisplay));

then in the header template:
HTML Code:
<script type="text/javascript">
var criteriaDisplay = "{vb:raw criteriaDisplay}";
</script>

and in the html source:
HTML Code:
<script type="text/javascript"> 
var criteriaDisplay = "5";
</script>

ETA: I have version 4.1.3, maybe there was some problem before that version.
Reply With Quote
  #5  
Old 05-31-2011, 02:35 AM
TWood's Avatar
TWood TWood is offline
 
Join Date: Mar 2009
Location: Washington DC
Posts: 96
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Weird... I'm also using 4.1.3

Would it be okay to create a plugin that had just this part at global_start:

Code:
vB_Template::preRegister('header',array('criteriaDisplay' => $criteriaDisplay));

I actually have the Javascript in headinclude, if that makes any difference. So the plugin would be:

Code:
vB_Template::preRegister('headinclude',array('criteriaDisplay' => $criteriaDisplay));
Reply With Quote
  #6  
Old 05-31-2011, 02:47 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, that should be OK. But if it's coming out in the <p>{vb:raw criteriaDisplay}</p> in the same template (headinclude) then whatever you're doing must already be makign the variable available. (if you're putting that in a different template then the problem might be that $criteriaDisplay isn't set yet when header is rendered).

I just noticed that there's already a bunch of js vars defined the same way in headinclude, so I don't know why yours wouldn't work the same way.
Reply With Quote
  #7  
Old 05-31-2011, 02:57 AM
TWood's Avatar
TWood TWood is offline
 
Join Date: Mar 2009
Location: Washington DC
Posts: 96
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

My bad, actually the <p>{vb:raw criteriaDisplay}</p> is in the searchresult_list template, which comes after the header info. So by then it's available. I'll try the plugin.
Reply With Quote
  #8  
Old 05-31-2011, 03:01 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ah...that's probably it. But the plugin won't help unless the $criteriaDisplay variable has a value set (not just preregistered) before the header is rendered. That might be what the DevShed person was trying to get at. You might have to juggle things around to get it to work out.
Reply With Quote
  #9  
Old 05-31-2011, 03:05 AM
TWood's Avatar
TWood TWood is offline
 
Join Date: Mar 2009
Location: Washington DC
Posts: 96
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, no go on the plugin. I'll try moving the Javascript for the ads to the searchresult_list template. I know they want it in the header so it's global, but it just won't do it.

--------------- Added [DATE]1306815435[/DATE] at [TIME]1306815435[/TIME] ---------------

Success!

Moving the ad code down to the searchresult_list template is all it needed.

kh99 - Thank you for your help!
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 10:25 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.09457 seconds
  • Memory Usage 2,243KB
  • 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
  • (5)bbcode_code
  • (3)bbcode_html
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)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