Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-20-2010, 08:02 AM
kharmer kharmer is offline
 
Join Date: Jul 2010
Location: Herts, UK
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Custom Profile Field - Add to 'Edit Email & Password' (modifypassword template)

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:

PHP Code:
{vb:raw profile.field5
Thanks,
Kris...

--------------- Added [DATE]1282311891[/DATE] at [TIME]1282311891[/TIME] ---------------

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...
Reply With Quote
  #2  
Old 08-20-2010, 02:25 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 08-23-2010, 01:45 PM
kharmer kharmer is offline
 
Join Date: Jul 2010
Location: Herts, UK
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.

PHP Code:
vB_Template::preRegister('modifypassword',array('myplugin_output' => 'ABCDEFG')); 
Using the following in the target template (modifypassword) works:

PHP Code:
{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...
Reply With Quote
  #4  
Old 08-23-2010, 02:08 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 08-23-2010, 02:29 PM
kharmer kharmer is offline
 
Join Date: Jul 2010
Location: Herts, UK
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.

PHP Code:
## 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('RTRvalues' => $customfields)); 

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

PHP Code:
{vb:raw RTRvalues.ReferingHostName
PHP Code:
{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...
Reply With Quote
  #6  
Old 08-24-2010, 03:15 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 08-24-2010, 08:22 AM
kharmer kharmer is offline
 
Join Date: Jul 2010
Location: Herts, UK
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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...
Reply With Quote
  #8  
Old 09-06-2010, 04:29 PM
mokonzi's Avatar
mokonzi mokonzi is offline
 
Join Date: Nov 2007
Location: SW Scotland
Posts: 137
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:36 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04391 seconds
  • Memory Usage 2,239KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete