Announcement
Collapse
No announcement yet.
How to affect variables in template hooks?
Collapse
X
-
Thanks everyone for the information and insight. I will use the API to solve this.
-
Originally posted by raywjohnson View PostThat works as expected. In the template, I can view and change values. All good.
However, templates don't send values between each other. Think of each template as a PHP function or method. Its variables are Local to it. You should set the variable in the template it is needed in.controls=controls
to the template hook call, the PHP API in vBulletin makes the value available as a local template variable through a registration process.
You should set your value in the conversation_footer template.
Leave a comment:
-
You could not set variables in hook templates and give those back to the parent. It is one way from parent to hooked child.
This could only been done by api. But only if templates not save as files.
Leave a comment:
-
Thanks for the info.
But as I mention in the post:
Hook Arguments: controls=controls
That works as expected. In the template, I can view and change values. All good.
But, any changes to the values are lost in the calling template.
Start in template: conversation_footer
Hook in that template: conversation_footerright
Template hook:
Hook Location: conversation_footerright
Template Name: hook_change_vote_ctrl
Hook Arguments: controls=controls
In template hook_change_vote_ctrl, hange controls value: {vb:set controls.showVoteCtrl, 1}
But... back in conversation_footer, the change is lost.
I used {vb:debugvardump} in both templates to verify that the change has not effect.
Leave a comment:
-
You can pass variables to your custom template using the Hook Arguments field in the Template Hook Manager.
Use this field to enter any arguments to be passed from the parent template to the called template.
Enter each variable assignment on a new line as "varname=var-to-pass". For example
userinfo=userinfo
userid=userinfo.userid
Note that only variables can be passed, use the dot syntax to pass array elements.
However, templates don't send values between each other. Think of each template as a PHP function or method. Its variables are Local to it. You should set the variable in the template it is needed in.
Leave a comment:
-
How to affect variables in template hooks?
Greetings,
How to change the value of a variable in a template hook that affects the variable in the parent that calls the hook?
Setup is...
In Template:
conversation_comment_item
Contains this:
{vb:template conversation_footer, conversation={vb:raw conversation}, controls={vb:raw footerControls}}
In Template:
conversation_footer
Contains this:
{vb:hook 'conversation_footerright'}
So template conversation_comment_item calls template conversation_footer and passes footerControls as controls.
conversation_footer contains the hook: conversation_footerright
I added a template hook:
Hook Location: conversation_footerright
Template Name: hook_change_vote_ctrl
Hook Arguments: controls=controls
Created template: hook_change_vote_ctrl
Which contains only this...
{vb:set controls.showVoteCtrl, 1}
All this works as expected, except it has no effect on the "controls" variable in the parent template.
So the hook system does not allow changes to variables just using templates and hooks?
Or did I missing some step?
--
{vb:debugvardump}Tags: None
Related Topics
Collapse
-
by darkboy245How can I make {vb:raw forum.nodeid} work in a custom template? I'm trying to fetch the current ID of the forum that I'm viewing so I can create a custom URL with it, but the variable won't register....
-
Channel: Support Issues & Questions
Tue 11 May '21, 6:06am -
Leave a comment: