The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
![]()
I want to create a variable and use it in template conditionals in a few places. So far I'm not getting the scope right, or I haven't figured out the right way to access it within the templates...
I've created a plugin with just this code in it: Code:
include('./plugins/my_mod.php'); Code:
<?php foreach ($vbulletin->forumcache as $forumdata) { if ( strpos($forumdata["description"], '<!-- something -->') !== false ) { $something[] = $forumdata["forumid"]; } } ?> The plugin needs to affect the forumhome_forumbit_level1_nopost template as well as the display of navbits in forumdisplay and showthread, at least. Which hook should I use to make sure the variable $something will be valid when and accessible where I need it? How do I reference the variable from a template? I've written and tested template conditionals using vbulletin class variables, so I've got the basic syntax working okay. How do I make a variable I create have the same sort of scope? Finally, as an aside, is hiding stuff in the forum description a really stupid way to customize something to begin with? Thanks! All help will be much appreciated. Mike D. |
#2
|
|||
|
|||
![]()
You could add a global $something in the top.
And yes, hiding something in the title is not a good way. |
#3
|
|||
|
|||
![]() Quote:
I'm still learning php. I thought $global allows a function to use a variable that has scope in the place the function is called from. I have not seen anything to indicate that it forces a variable used in the function to have scope in the script that is calling it. Is that what you're saying? [edit: I realize the snippet of code in my_mod.php isn't a function. It still leaves the question of how to make a variable global in scope?] Quote:
Rather than have code hidden away in a template that has to be hand tweaked if I decide to change the setting on a forum, it would be ideal to add a new forum attribute, just like post/nopost or colors, or whatever. Hiding something in the forum description that won't be displayed looks like one way to accomplish that without hacking the code. In fact, not only does it not display, it doesn't even get sent to the browser as an html comment. I've been trying to avoid modifying vBulletin code. In fact, I haven't even looked at any of the adminCP code or templates yet. If I really can't do this in a clean way without a hack, I guess now is the time to learn. Is it possible to add my extra forum attribute as a template mod to the adminCP? If not, please point me in the right direction and give me a nudge? I don't even know where to start looking. <sigh> Thanks, Mike D. |
#4
|
|||
|
|||
![]() PHP Code:
For adding new options to a Forum, see: https://vborg.vbsupport.ru/showthread.php?t=93445 |
#5
|
|||
|
|||
![]() Quote:
Quote:
Also, that raises a question about the plugin system. I was thinking that the my_mod.php file was being included, but it must be being executed within a call to the fetch_hook function. If the $global pushes the variable scope up to the calling context, then it makes sense. Do I have that right? Quote:
That looks like exactly what I'm trying to do, Marco. Bless you! I'll try the $global statement and get it working my way. Then I'll go back and do it the right way. ![]() Thank you for the help. Be well, Mike D. |
#6
|
|||
|
|||
![]()
It is not the plugin system itself that create a new scope. But some hooks are called from the main scope, and some are called from within a function. Hence sometimes you will need a global $var, and sometimes not.
|
#7
|
|||
|
|||
![]()
Okay, I have my variable showing up where I wanted, but I still have a question, below.
I had to analyse the way the scripts call each other and the templates before I could get things right...
The hook named forumbit_display, which is near the end of construct_forum_bit, now contains: PHP Code:
The forumhome_forumbit_level1_nopost template now contains this (the code I added is in color): Code:
<tbody> <tr> ...code that shows the moderator column if enabled... <if condition="in_array($forum[forumid],$something)"> $forum[title] <else /> ...original code that displays the forum title as a link, and the collapse button... </if> ...code that displays the forum description... </tr> </tbody> ...code that displays any subforums... The only problem is that when I put the in_array($forum[forumid],$something) function in the template conditional and try to save the template, it reports: Quote:
So am I bumping up against a limitation of the Template Manager's parsing algorythms, or what? Is my code still flawed, despite the fact it works? I'd like these final questions answered so I can learn all I can from this attempt, before I move on to doing it the way Marco suggested above. I'm getting better. I really am! ![]() Mike D. |
![]() |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|