The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
How to call a variable from within the Threadbit template?
I'm trying to convert over a vb3 product to vb4, and am running into an issue with the template system. Specifically, I am having trouble passing a variable to be outputted from within the template.
I am using the following code in a plugin which has the hook location of threadbit_display: PHP Code:
{vb:raw custom_template} Unfortunately, it didn't work. Also tried {vb:raw custom_template.my_var} and it didn't work. I've turned on dev mode, and custom_template appears under the list of template usage. It is highlighted in red though - I don't know what that means. Anyone have any ideas? |
#2
|
||||
|
||||
PHP Code:
|
#3
|
|||
|
|||
Thanks Lynne - I copied and pasted that code exactly though, and it still didn't work... I changed $my_var to "Test123" just to make sure it was a variable assignment error or anything, but still a no go.
It is ok to be including this code in a plugin which uses hook location threadbit_display, correct? |
#4
|
||||
|
||||
Do you know if it is your template that isn't rendering or the preregistering that isn't working? Do some debugging in that area to find out (just assign xxx to a variable and preregister is and see if it shows up).
|
#5
|
|||
|
|||
Hi Lynne - That is exactly what I did - I assigned the value "Test123" to the variable, so it looks like it is the pre-registering which isn't working...
For example - Code:
$templater = vB_Template::create('custom_template'); $templater->register('my_var', 'Test123'); $custom_template = $templater->render(); vB_Template::preRegister('threadbit', array('custom_template' => $custom_template)); |
#6
|
||||
|
||||
This works just fine for me, so preregistering is working:
PHP Code:
|
#7
|
|||
|
|||
I'm a little mixed up - can I just use these two lines then, and insert whatever variable I want for $custom_template? I.e. is the 4 line version redundant, or do they both versions do the same thing?
|
#8
|
||||
|
||||
You could just do it with two lines. I thought you had a template you were wanting to use though.
|
#9
|
|||
|
|||
Well, I think I should be using templates in order to use the cache system, correct? I.e. if I just use pre-register no caching will occur, right?
--------------- Added [DATE]1262298647[/DATE] at [TIME]1262298647[/TIME] --------------- Also - just to clarify - i am able to access the variable using the 2 line version, but when I register as a template I am unable to access the variable. When I turn on debug mode I can confirm the template is being loaded though. There is a (20) beside it, and its name is highlighted in red (which I assume means its not cached?) |
#10
|
||||
|
||||
I would guess something is wrong with your template then. Try just putting "hello" in the template and see if you get that to print out.
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|