The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
Using template hooks vs. manual insertion into template
Hello!
I added some custom options to usercp after I read this great tutorial https://vborg.vbsupport.ru/showthread.php?t=116155 Instead of manually editing a template like in this tutorial I wanted to use a template_hook in order to make a product that is easy install for others. At first I inserted this code directly into the modifyoptions template (as suggested in the tutorial): Code:
<fieldset class="fieldset"> <legend><label for="cb_allowsioc">Export SHA1</label></legend> <table cellpadding="0" cellspacing="$stylevar[formspacer]" border="0" width="100%"> <tr> <td> Export encrypted version of my e-mail address </td> </tr> <tr> <td><label for="cb_allowsioc"><input type="checkbox" name="siocbitoptions[allowsioc]" value="1" id="cb_allowsioc" $checked[allowsioc] />Export SHA1</label><input type="hidden" name="set_options[allowsioc]" value="1" /></td> </tr> </table> </fieldset> But when I add the code to the hook global_start using Code:
$template_hook[usercp_options_privacy] .= ' [same as above] '; When I look at the usercp, the checkbox is never checked - it remains empty even tough in the userinfo I can see a 1 where it should be. Can anyone see where the problem is? |
#2
|
|||
|
|||
You can't place variables inside single quotes. Make sure you use double quotes in the global_start hook or you escape out of the quotes.
PHP Code:
Also make sure you surround array keys by single quotes when you write in PHP e.g. PHP Code:
|
#3
|
||||
|
||||
Thanks Opstery, good hint, but still I couldn't get it to work.
Now I have it like this: Code:
$template_hook['usercp_options_privacy'] .='<fieldset class="fieldset"> <legend><label for="cb_allowsioc">Export SHA1</label></legend> <table cellpadding="0" cellspacing="'.$stylevar[formspacer].'" border="0" width="100%"> <tr> <td> Export encrypted version of my e-mail address </td> </tr> <tr> <td><label for="cb_allowsioc"><input type="checkbox" name="siocbitoptions[allowsioc]" value="1" id="cb_allowsioc" '.$checked[allowsioc].' />Export SHA1</label><input type="hidden" name="set_options[allowsioc]" value="1" /></td> </tr> </table> </fieldset> '; Somehow I suspect there is another obvious thing I am missing - any other suggestions what might be wrong? Maybe another hook location instead of global_start? |
#4
|
|||
|
|||
Oh wait, your using global_start aren't you. You need to choose somewhere "closer" to your page. Find a hook in the PHP in which the original template shows, then choose a hook from there. Make sure that $checked[allowsioc] is actually been set somewhere too and also that the template hook is assigned after $checked[allowioc] is set.
|
#5
|
||||
|
||||
Okay, after quite a while I found the problem: there is no appropriate hook location.
In profile.php there is the hook "profile_editoptions_start" which is closest to where I need it - but the code that checks the checkboxes is only executed just right after it: Code:
($hook = vBulletinHook::fetch_hook('profile_editoptions_start')) ? eval($hook) : false; // check the appropriate checkboxes $checked = array(); foreach ($vbulletin->userinfo AS $key => $val) { if ($val != 0) { $checked["$key"] = 'checked="checked"'; } else { $checked["$key"] = ''; } } And the next hook "profile_updateoptions" is already "too late" - nothing gets displayed at all when I use this hook! I edited profile.php and moved the first hook just a couple of lines down, and then everything worked perfectly - but of course I would prefer if the people who install my product wouldn't have to do that, too. Should I request a new hook / a change of the hook location? Or is there any other way to deal with that? (I am running the latest version of 3.6.8) |
#6
|
|||
|
|||
Why don't you just do something like this in your plugin?
PHP Code:
|
#7
|
||||
|
||||
Hi Opserty!
The saving of the status userinfo['allowioc'] wasn't the problem, just the checkbox didn't get checked when it was true - but your point remains valid: I just added another plugin that takes care of checking my custom checkboxes at the same hook location with higher priority in the execution order and it now seems to work as needed Thank you very much! :up: |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|