PDA

View Full Version : Custom Profile Field - Add to 'Edit Email & Password' (modifypassword template)


kharmer
08-20-2010, 08:02 AM
Hi all,

How do I reference a Custom Profile Field in 'edit profile' type templates?

I need to add a custom field to the 'modifypassword' template; in other templates (i.e. signature area in postbit) I have referenced them like this:

{vb:raw profile.field5}

Thanks,
Kris...

--------------- Added 1282311891 at 1282311891 ---------------

The way I called custom profile fields in places like postbit templates is as indicated above.

So, how would I call the same custom profile fields from somewhere like the 'modifypassword' template?

Are custom profile fields actually in scope in these templates? And if not, how should I go about making them available (custom code in a hook!)?

Any pointers on this would be very much appreciated,
Kris...

Lynne
08-20-2010, 02:25 PM
Do a search in your files for 'modifypassword' (with the single quotes) and you should find where it is rendered and you will also find which variables are registered for use in that template. Unfortunately, there are no variables registered for use in that template (take a look at it and you'll only see phrases and $show which doesn't need to be registered). So, if you want to use some variables in there, you will have to preregister them for use.

kharmer
08-23-2010, 01:45 PM
Thanks for the pointer Lynne,

OK, so I have created a plugin in the 'global_bootstrap_init_start' hook.

This plugin contains the following 'test code' to preregister some dummy variables into the desired template.

vB_Template::preRegister('modifypassword',array('m yplugin_output' => 'ABCDEFG'));

Using the following in the target template (modifypassword) works:

{vb:raw myplugin_output}

So, my next questions are ;o)

> How do I get the custom profile field values into my plugin? Do I have to run a database query? Or is there a smarter way?

> Should I be using the 'global_bootstrap_init_start' hook; I got it to work with the 'profile_editpassword_start' hook too?

> Should I use the 'global_bootstrap_init_start' hook and simply register all variables I'll need so I can implement them across multiple templates if needed?

> Should I just be registering these values in the individual templates where needed?

Thanks in advance for any pointers/advice,
Kris...

Lynne
08-23-2010, 02:08 PM
Is this just the users/viewers fieldx? My guess is it may already have been queried and is available as variable $vbulletin->userinfo['fieldx'] . So, you could try using that.

You should only register a variable for use in the template you need to use it in.

kharmer
08-23-2010, 02:29 PM
Yes, you're right. The user profile fields for the logged in user are already queried and your example works.

I now have in my plugin in the 'global_bootstrap_init_start' hook.

## Create array of custom user profile fields
$customfields = array(
'ReferingHostName' => $vbulletin->userinfo['field5'],
'ReferingHostMemberCode' => $vbulletin->userinfo['field6']);

## preRegister variables for desired templates
# For 'modifypassword' template
vB_Template::preRegister('modifypassword',array('R TRvalues' => $customfields));


And I can refer to each of these like so (in the 'modifypassword' template).

{vb:raw RTRvalues.ReferingHostName}

{vb:raw RTRvalues.ReferingHostMemberCode}


With regards to the hook I amusing; should I use a more specific hook for 'modifypassword' template (if that was all I needed) so that it isnt invoked when not required? I was thinking of unnecessary overheads!

Thanks for your help Lynne, you're a star,
Kris...

Lynne
08-24-2010, 03:15 AM
If you turn on debug mode (add "$config['Misc']['debug'] = true;" to the config.php file), then you will see a list of all the hook locations called on the page in order. You can try those hook locations and see if there is a better, more local, one.

kharmer
08-24-2010, 08:22 AM
Thanks again Lynne; I've found a couple of hooks that are much more local/specific for the template I am preRegistering my custom variables for.

Kris...

mokonzi
09-06-2010, 04:29 PM
Just looking at this thread, how would I be able to utilize the array as a conditional? i.e. check that what it contains equals something?

I'm trying to get a check done on a ProfileField entry, and then if it exists, do display or remove part of the template.

Any suggestions?