vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 5 Connect Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=249)
-   -   [vB5] User Profile Fields in the postbit templates (https://vborg.vbsupport.ru/showthread.php?t=297041)

Lynne 04-09-2013 10:00 PM

[vB5] User Profile Fields in the postbit templates
 
1 Attachment(s)
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:
https://vborg.vbsupport.ru/attachmen...1&d=1365552264

Image 2:
https://vborg.vbsupport.ru/attachmen...1&d=1365552264
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'];




abdobasha2004 04-12-2013 10:41 PM

thanks lynne
great work

Wayne Luke 04-13-2013 03:18 PM

Great tutorial thanks.

greygaming 05-02-2013 02:12 PM

how would you go about adding the link as an attribute inside of an img tag?

or is it more involved than just chopping up that string and putting it in whatever tags you need?

Lynne 05-02-2013 05:24 PM

Quote:

Originally Posted by greygaming (Post 2419615)
how would you go about adding the link as an attribute inside of an img tag?

or is it more involved than just chopping up that string and putting it in whatever tags you need?

I don't know what you mean at all. Can you give an example? You can change the template up however you want. I was just giving an example to make it look like the other stuff under the avatar, but you may format it/change it however you want.

greygaming 05-03-2013 11:58 PM

I would like to take the text string from the text field and have it inserted in the href attribute of an anchor tag. I would then use the anchor tag to wrap around an icon.

any thoughts?

thanks for the reply

Lynne 05-04-2013 03:16 AM

Quote:

Originally Posted by greygaming (Post 2419827)
I would like to take the text string from the text field and have it inserted in the href attribute of an anchor tag. I would then use the anchor tag to wrap around an icon.

any thoughts?

thanks for the reply

So you aren't talking about using a profile field at all, but the text. That isn't what this tutorial is about.

greygaming 05-04-2013 12:18 PM

okay.

official vbulletin support pointed me here and said it could be done.

thanks anyway

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

I am unable to create new articles on this site, and vBulletin support is no help.

Would you have any information or resources that I could read up on this topic by myself?

I'm just getting surprised at this point by the lack of help and resources on modifying vbulletin 5.

Lynne 05-04-2013 06:29 PM

Quote:

Originally Posted by greygaming (Post 2419898)
okay.

official vbulletin support pointed me here and said it could be done.

thanks anyway

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

I am unable to create new articles on this site, and vBulletin support is no help.

Would you have any information or resources that I could read up on this topic by myself?

I'm just getting surprised at this point by the lack of help and resources on modifying vbulletin 5.

This article is about using the Profile Fields in the postbit template. If that is what you are talking about, then it isn't apparent to me. Perhaps you can be a lot more specific about what you want and then we could help. Vague questions will not get very specific responses.

greygaming 05-05-2013 05:27 PM

I'm sorry for crappy explanations, I do appreciate you taking the time to read these posts


http://imgur.com/rbTHBpa

The picture above is the postbit I am looking to create.
Each image is tied to a link, each link is just the contents of the corresponding profile field.
What I am asking is how to make the output an image of my choice, and have the contents of the field be the link for the image.
Does that make sense?


Isn't that essentially what this tutorial is about, minus the images?
(note: I don't need help with the styling, I can figure that out)

sorry for any misunderstanding or time wasted, i did not mean to offend

Lynne 05-05-2013 06:34 PM

If your profile field is a link - http://something.com/image.png - then just use an image tag:

HTML Code:

<img src="{vb:raw userInfo.customFields.category1_title.field7_title.val}" alt="something" height="yy" width="xx" />

greygaming 05-05-2013 06:42 PM

gorgeous.


thank you so much for your help

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

Now, I'm actually curious if there is a way to do the exact same thing in the profile area.

Instead of the field.value being displayed on the profile page, could it be replaced with an image in the exact same way as in the postbit template?

thanks for placating my curiosity!

Lynne 05-05-2013 10:19 PM

Quote:

Originally Posted by greygaming (Post 2420106)
gorgeous.


thank you so much for your help

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

Now, I'm actually curious if there is a way to do the exact same thing in the profile area.

Instead of the field.value being displayed on the profile page, could it be replaced with an image in the exact same way as in the postbit template?

thanks for placating my curiosity!

Sorry I didn't understand at first what you were looking for. I'm glad we were finally able to get it working!

You could probably do something similar on the profile page, but I don't see a hook there so it looks like you would need to edit the widget_profile_sidebar template manually to do it. I haven't looked into it at all, but my guess is the variable names will be different also.

korny 05-17-2013 03:46 PM

I am getting this error:

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

Not sure what I am missing in the install.

Lynne 05-17-2013 04:12 PM

Quote:

Originally Posted by korny (Post 2422705)
I am getting this error:

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

Not sure what I am missing in the install.

And exactly what did you enter into your template? (Use code tags)

korny 05-22-2013 08:51 PM

Code:

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

<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>
Thanks

Lynne 05-23-2013 01:05 AM

You have two different code sections above, why? Are they in two different templates or what? Is that all that is in the template? And can we get a screenshot of your Field 5 edit page so we can we it's field id and type and category, etc. And did you create the hook and is the plugin system enabled?

korny 05-23-2013 06:26 PM

1 Attachment(s)
Sorry about the 2 code fields. I have the below in the new conversation_fields template

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>

I have added the hook as instructed in this thread.
The hook system is on.
My new field is uncategorized field 5.


Attachment 145161


Thanks Lynne!

Lynne 05-23-2013 07:07 PM

Is there some odd text in the text box for that field for the user?

I honestly see nothing wrong with what you have. I'd try removing some of it and seeing if you can see exactly what part of that template is causing the error.

korny 05-23-2013 08:56 PM

The error I originally posted comes up when I save the template. I haven't added anything else to the template besides an additional_css mod to make the header logo larger. Other than that my vB version is completely default.

How would I go about completely removing what I have done thus far and starting over?

Lynne 05-24-2013 04:28 PM

Just delete the template and delete the hook and it's gone.

korny 05-24-2013 10:21 PM

Ok, so I played around with the code to see if I could get it to at least save without any errors. By changing

Code:

"$userInfo['field5']"
to

Code:

"$userinfo['field5']"
(lower case i)

...the template saved and reloaded. Then I changed it back to capital "Info", still got the error but when I clicked Go Back, it pushed through and saved all of a sudden. :confused:

Then the Custom Profile field is displayed in the postbit...but overlapped the Online status button. I added a <br> underneath the conversation_userstats hook in the coversation_userinfo template and it seems to all be working correctly now.

Hopefully this will help the next person!

:erm:

Lynne 05-25-2013 02:27 AM

Hmmmm, are you sure your hooks are enabled and you have a hook written (and active) exactly like what I wrote?

korny 05-26-2013 12:07 AM

Yes, hook system is on and the hook is written exactly as you wrote. I don't know that my issue was caused by my error or your mod. By performing a quick search I found 1 other person who had the same issue, but he/she posted on vb.com and was directed here without resolution. The point is that it now works with the only changes being the line break I had to put in to align the postbit correctly. With the amount of errors and bugs I have already encountered with vB5 I can't say I'm surprised!

discover_xs 06-14-2013 08:46 AM

Exactly the same thing here
When creating the template it self
i get this:

Warning: Illegal string offset 'field5' in [path]/includes/adminfunctions_template.php(4704) : eval()'d code on line 2

v. 5.0.2

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>


After saving it with a lower case I
it saved but its not showing up.

Hooks are active and set exactly as instructed.
Template name is the same
everything is the same but it does not show up.
Do i need to add something to conversation_userinfo
to make it show up?


wow i made it work by putting 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>

in conversation_userinfo
where i want the gender to be displayed.


Now another question:

Field is Gender
and can i set an image to show for each choice?
(male / female signs)

Lynne 06-14-2013 05:28 PM

Very odd. I cannot get it to give me that error at all on either of my test sites when I enter exactly what you guys are entering.

Do you have the plugin system enabled?

As for an image, just use a condition:
Code:

<vb:if condition="$userInfo['field5'] == 'female'">image code here
<vb:else /> other image code here
</vb:if>


discover_xs 06-14-2013 06:33 PM

nope.
nothing ON right now

hmmm... really strange

check your pm
some private details there.

if we find a solution it will be posted ;)



thank you for the IMG thing .. i will check it as soon as possible and report back to you

Admigo 08-08-2013 11:05 AM

I have a problem with this code.
I made a text profile field but only the title is showing in the postbit.
Example: CnR Username :
I already changed the CnR Username in my profile.
How to fix it for not showing as blank?

Lynne 08-08-2013 08:23 PM

Post your exact code or it's impossible to help.

Admigo 08-08-2013 08:27 PM

Quote:

Originally Posted by Lynne (Post 2437908)
Post your exact code or it's impossible to help.

Here you go:
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.category5_title.field5_title.val}</span></li></vb:if>


Lynne 08-08-2013 08:34 PM

And you are positive the catid is 5?

Admigo 08-08-2013 08:39 PM

Quote:

Originally Posted by Lynne (Post 2437917)
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.

astrid1 08-12-2013 08:26 AM

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

Lynne 08-12-2013 04:41 PM

Post your exact template. And did you make sure to enable the plugin system (it is off by default) and create the Hook?

astrid1 08-13-2013 09:19 AM

1 Attachment(s)
Quote:

{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>

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

astrid1 09-23-2013 10:37 AM

Lynne?

Lynne 09-23-2013 04:17 PM

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.

heredia21 12-08-2013 05:56 AM

Perfect Lynne! Just what I was looking for. We need some more of these how-tos!

ndut 01-12-2014 02:49 PM

1 Attachment(s)
@Lynne,

my command :

Quote:

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

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

<vb:if condition="$userInfo['field3']"><li><label>{vb:phrase 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 (Post 2447476)
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 :
https://vborg.vbsupport.ru/attachmen...1&d=1389543242

ndut 01-23-2014 02:44 PM

Hello, Lynne.....


All times are GMT. The time now is 02:05 PM.

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.02562 seconds
  • Memory Usage 1,871KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (12)bbcode_code_printable
  • (1)bbcode_html_printable
  • (2)bbcode_php_printable
  • (13)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete