Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 5 Connect Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
[vB5] User Profile Fields in the postbit templates
Lynne's Avatar
Lynne
Join Date: Sep 2004
Posts: 41,180

 

California/Idaho
Show Printable Version Email this Page Subscription
Lynne Lynne is offline 04-09-2013, 10:00 PM

Using your User Profile Fields on your site

This article is written with the assumption that you have already created your own User Profile Fields in the User Profile Field Manager. If you need help with this, you may read about it in the manual here - http://www.vbulletin.com/docs/html/profile

For the Purposes of this article, I will be referring to "fieldx" as the name of your profile field. Your real name will be found in the User Profile Manager in the "Name" column - field1, field2, etc.


First thing to do is figure out which fields you want to add to your postbit. Go to your Admincp > User Profile Fields > User Profile Field Manager and note both the Field Name (field1, field2, etc) and the Category the field is in (see image 1). The Profile Fields are listed under their Category Title on this page. It should either be "(Uncategorized)" or have some other category listed. To then get the Category ID, go to User Profile Field Categories, click to Edit the category you want the ID of, and it will be listed at the top - id x (see image 2). Uncategorized Categories have no Category ID.
Image 1:


Image 2:
So, now that you have a list of field ids and category ids, you can now easily add them to your postbit.

First make sure your hook system is active (it is turned off by default). Go to Admincp > Settings > Products/Hook System > Enable/Disable Hook System > Yes.

Now, go to Admincp > Products & Hooks > Manage Hooks and click the link that says "[Add New Hook]". In that new hook, set the following:
Hook is Active: Yes
Hook Location: conversation_userstats
Title: Show Profile Fields in Postbit
Template Name: conversation_fields
Hook Arguments: conversation=conversation
SAVE
Now go to Admincp > Styles & Templates > Style Manager > Add New Template and on that page, set the following:
Title: conversation_fields
Template:
Code:
{vb:data userInfo, user, fetchProfileInfo, {vb:raw conversation.userid}}
For each field you want shown, you will need to add this code under that line:
Code:
<vb:if condition="$userInfo['fieldX']"><li><label>{vb:phrase fieldX_title}:</label> <span>{vb:raw userInfo.customFields.default.fieldX_title.val}</span></li></vb:if>
Replace the X in "FieldX" (three times) with the fieldid and, if your field is in a Category other than Uncategoried, then replace "default" with "categoryY_title" where Y is the category id.

So, for instance, say I have the following I want to add:
Name Category
field5 (uncategoried)
field7 New Cat(id 1)
Then my template would look like this:
Code:
{vb:data userInfo, user, fetchProfileInfo, {vb:raw conversation.userid}}

<vb:if condition="$userInfo['field5']"><li><label>{vb:phrase field5_title}:</label> <span>{vb:raw userInfo.customFields.default.field5_title.val}</span></li></vb:if>

<vb:if condition="$userInfo['field7']"><li><label>{vb:phrase field7_title}:</label> <span>{vb:raw userInfo.customFields.category1_title.field7_title.val}</span}</li></vb:if>
That's it!

If running 5.1.0, there is a code fix to apply here.

Quote:
Originally Posted by Zachery
In the templates, after applying the following change to

core/vb/library/content/text.php

Find

PHP Code:
 if (!$canseehiddencustomfields)
{
// Get profile fields information
$fieldsInfo vB_Cache::instance(vB_Cache::CACHE_STD)->read('vBProfileFields');

if (empty(
$fieldsInfo))
{
$fieldsInfo $this->assertor->getRows('vBForum:profilefield');
vB_Cache::instance(vB_Cache::CACHE_STD)->write('vBProfileFields'$fieldsInfo1440, array('vBProfileFieldsChg'));
}

foreach (
$fieldsInfo as $field)
{
$fields['field' $field['profilefieldid']] = $field['hidden'];
}

Change it to:

PHP Code:
// Get profile fields information
$fieldsInfo vB_Cache::instance(vB_Cache::CACHE_STD)->read('vBProfileFields');
  if (empty(
$fieldsInfo))
{
$fieldsInfo $this->assertor->getRows('vBForum:profilefield');
vB_Cache::instance(vB_Cache::CACHE_STD)->write('vBProfileFields'$fieldsInfo1440, array('vBProfileFieldsChg'));
}
  foreach (
$fieldsInfo as $field)
{
$fields['field' $field['profilefieldid']] = $field['hidden'];

Attached Images
File Type: png UPF Categories.png (25.5 KB, 0 views)
File Type: png UPF Manager.png (62.7 KB, 0 views)
Reply With Quote
  #32  
Old 08-08-2013, 08:34 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

And you are positive the catid is 5?
Reply With Quote
  #33  
Old 08-08-2013, 08:39 PM
Admigo Admigo is offline
 
Join Date: Aug 2013
Posts: 4
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
And you are positive the catid is 5?
Yes. User Profile Field: CnR Username (id: 5 - input)
The title is showing fine in the postbit but not my CnR Username.
So CnR Username : blank

EDIT: I fixed it. I didnt made a category. Thanks for your help.
Reply With Quote
  #34  
Old 08-12-2013, 08:26 AM
astrid1 astrid1 is offline
 
Join Date: Mar 2008
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Also have problems in 5.0.3 there was no problem
now 5.04 based on a new installtion I get this error

Warning: Illegal string offset 'field5' in [path] / includes / adminfunctions_template.php (4723): eval () 'd code on line 2
Reply With Quote
  #35  
Old 08-12-2013, 04:41 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Post your exact template. And did you make sure to enable the plugin system (it is off by default) and create the Hook?
Reply With Quote
  #36  
Old 08-13-2013, 09:19 AM
astrid1 astrid1 is offline
 
Join Date: Mar 2008
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
{vb:data userInfo, user, fetchProfileInfo, {vb:raw conversation.userid}}

<vb:if condition="$userInfo['field5']"><li><label>{vbhrase field5_title}:</label> <span>{vb:raw userInfo.customFields.default.field5_title.val}</span></li></vb:if>

<vb:if condition="$userInfo['field7']"><li><label>{vbhrase field7_title}:</label> <span>{vb:raw userInfo.customFields.category1_title.field7_title .val}</span}</li></vb:if>

Quote:
The following error occurred when attempting to evaluate this template:

Warning: Illegal string offset 'field2' in [path]/includes/adminfunctions_template.php(4723) : eval()'d code on line 3

Warning: Illegal string offset 'field7' in [path]/includes/adminfunctions_template.php(4723) : eval()'d code on line 9

This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wis
and since the error message is the temple will not be stored
Attached Images
File Type: jpg hook1.jpg (53.0 KB, 0 views)
File Type: jpg hook2.jpg (20.0 KB, 0 views)
File Type: jpg hook3.jpg (28.4 KB, 0 views)
File Type: jpg hook4.jpg (37.2 KB, 0 views)
File Type: jpg hoook6.JPG (47.2 KB, 0 views)
File Type: jpg hook7.jpg (32.4 KB, 0 views)
Reply With Quote
  #37  
Old 09-23-2013, 10:37 AM
astrid1 astrid1 is offline
 
Join Date: Mar 2008
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Lynne?
Reply With Quote
  #38  
Old 09-23-2013, 04:17 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That is my example template. I doubt yours would be exactly the same. Post images of your admincp > User Profile Field Manager and the Categories.
Reply With Quote
  #39  
Old 12-08-2013, 05:56 AM
heredia21 heredia21 is offline
 
Join Date: May 2013
Posts: 39
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Perfect Lynne! Just what I was looking for. We need some more of these how-tos!
Reply With Quote
  #40  
Old 01-12-2014, 02:49 PM
ndut ndut is offline
 
Join Date: Sep 2007
Location: Indonesia
Posts: 335
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

@Lynne,

my command :

Quote:
{vb:data userInfo, user, fetchProfileInfo, {vb:raw conversation.userid}}

<vb:if condition="$userInfo['field2']"><li><label>{vbhrase field2_title}:</label> <span>{vb:raw userInfo.customFields.default.field2_title.val}</span></li></vb:if>

<vb:if condition="$userInfo['field3']"><li><label>{vbhrase field3_title}:</label> <span>{vb:raw userInfo.customFields.default.field3_title.val}</span></li></vb:if>
and the error message is :

Quote:
The following error occurred when attempting to evaluate this template:

Warning: Illegal string offset 'field2' in [path]/includes/adminfunctions_template.php(4738) : eval()'d code on line 3

Warning: Illegal string offset 'field3' in [path]/includes/adminfunctions_template.php(4738) : eval()'d code on line 9

This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.
what should i do?


Quote:
Originally Posted by Lynne View Post
That is my example template. I doubt yours would be exactly the same. Post images of your admincp > User Profile Field Manager and the Categories.
and this is my screen shot :
Attached Images
File Type: jpg SS.jpg (71.5 KB, 0 views)
Reply With Quote
  #41  
Old 01-23-2014, 02:44 PM
ndut ndut is offline
 
Join Date: Sep 2007
Location: Indonesia
Posts: 335
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello, Lynne.....
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 09:14 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05482 seconds
  • Memory Usage 2,371KB
  • Queries Executed 26 (?)
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
  • (3)bbcode_code
  • (2)bbcode_php
  • (7)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (9)postbit_attachment
  • (11)postbit_onlinestatus
  • (11)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete