The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
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> 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:
Thanx |
#2
|
|||
|
|||
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> |
#3
|
||||
|
||||
Thanks kh99 -
Adding that script yields this in View Source: Code:
<script type="text/javascript"> var criteriaDisplay = ""; </script> Regarding the quote, yes it's the same page/template. |
#4
|
|||
|
|||
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. |
#5
|
||||
|
||||
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)); |
#6
|
|||
|
|||
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. |
#7
|
||||
|
||||
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.
|
#8
|
|||
|
|||
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.
|
#9
|
||||
|
||||
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! |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|