vBulletin Mods

The Official vBulletin Modifications Site
https://www.vbulletin.org/forum/showthread.php?t=250418

Using your User Profile Fields in your postbit templates (w/ all plugin method)
by Lynne
13 Sep 2010 15:57

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.

Adding the Profile Field to your postbit (or postbit_legacy) template

For Single-Line Text Box, Multiple-Line Text Box, Single-Selection Radio Buttons, and Single-Selection Menu

Method 1
- Modifying the Template
Open the postbit or postbit_legacy template and find the area you want to add it to. For instance, to add it right after the user post count, find this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

And then, add this underneath:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Change "fieldx" to your actual field name and the green field to whatever you want. Notice the html I used is similar to the html used for the text above me new field.
Method 2 - Using a template_hook
I have always found it easier to just use the existing $template_hooks in the template and write a plugin to add these. In this case, there is a $template_hook right where we want it, after the user post count:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

So, we would create a plugin with these specifications:
hook location - postbit_display_complete
Title - Add User Profile Fields to Postbit Templates
Plugin is Active - Yes
Plugin PHP Code -

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Change "fieldx" to your actual field name and the green field to whatever you want. Again, notice the html I used is similar to the html used for the text above me new field. Whichever template_hook you use, you should look at the template to see what sort of html is being used around the hook so that you may use similar, proper html also.
For Multiple-Selection Menu and Multiple-Selection Checkbox

It is a bit more complicated for these two types of selections since the options selected are stored as a binary number. If you just display the field using the method above, you will get a number, not a list of options selected. So, in order to use these types of fields, you will have to use the method below. Here is a thead that will explain the binary scheme - http://www.vbulletin.com/forum/showt...To-The-Postbit

Method 1
- Modifying the Template
Open the template and find the area you want to add it to. For instance, to add it right after the user post count, find this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

And then add this underneath (this is assuming the field has 5 options):

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Change "fieldx" to your actual field name and the green field to whatever you want. Notice the html I used is similar to the html used for the text above me new field.
Method 2 - Using a template_hook
Find the template_hook you want to use. In this case, there is a $template_hook right where we want it, after the user post count:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

So, we would create a plugin with these specifications:
hook location - postbit_display_complete
Title - Add User Profile Fields to Postbit Templates
Plugin is Active - Yes
Plugin PHP Code -

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Change "fieldx" to your actual field name and the green field to whatever you want. Again, notice the html I used is similar to the html used for the text above me new field. Whichever template_hook you use, you should look at the template to see what sort of html is being used around the hook so that you may use similar, proper html also.
More Advanced

If you like everything to be 'automatic' - meaning you don't have to supply any text at all, just use everything already stored in the database - then you can use a few of plugins to do the work for you.

Plugin 1
- This plugin is used to get the phrasegroup "cprofilefield" added for use in the page so that you may use $vbphrase[fieldx_title] to get the Profile Field Title you entered in the User Profile Field Manager.
hook location - init_startup
Title - Add User Profile Fields to Postbit Templates - 1
Plugin is Active - Yes
Plugin PHP Code -

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Plugin 2 - This plugin is used to get the fields you defined for the profile in the User Profile Field Manager.
hook location - showthread_postbit_create
Title - Add User Profile Fields to Postbit Templates - 2
Plugin is Active - Yes
Plugin PHP Code -

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Plugin 3 - This plugin simply spits the data out into the postbit using the template_hook and using the phrase for the Title and the Options are all spit out with commas between them (if needed) into the postbit.
hook location - postbit_display_complete
Title - Add User Profile Fields to Postbit Templates - 3
Plugin is Active - Yes
Plugin PHP Code -

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Change "fieldx" to your actual field name and the orange, purple, and brown fields should 'match-up' and have the same names.

Dave-M 14 Sep 2010 15:09

Hi Lynne, thanks for this, brilliant :)

I wonder if it would be possible for you to implement a dropdown for this, so that it's like wired1's mod? His has broken CSS at the moment and there's no sign of him being able to fix it soon, it would be fantastic if you could make something similar.

http://www.vbulletin.org/forum/showthread.php?t=248651

Lynne 14 Sep 2010 15:15

This is an article, not a modification. You may do whatever you want with the information found in here.

Lynne 20 Sep 2010 15:00

Quote:

Originally Posted by lightbox (Post 2100959)
Thanks a lot for this article.

Is there a way to use specific User Profile Fields in vbcms article pages (Template vbcms_content_article_page)?

Cheers,
Martin

I'm sure there is, but I didn't cover that in this article. This article is just for the postbit(_legacy) template.

svoophod 22 Sep 2010 22:30

thanks so much, this is great!

COL NIL SATIS 26 Sep 2010 18:13

Thanks lynne..this is great!!!! top advice ..

djr 15 Oct 2010 23:43

Hi Lynne,

Is it easy to backport this to vB 3.8.6? Besides the obvious variable name changes, would the plugin solution work for vB 3.8.6 as well? (meaning: does vB 3.8.6 have the same hooks present?). Or does it need to be completely rewritten?

I'd love to have this a plugin solution for our vB 3.8.6 board, since it's getting tiresome to redo all the template changes after every upgrade (plus I like the plugin solution better)

Thanks for an excellent article! Much appreciated.

Lynne 16 Oct 2010 00:00

The method of calling the phrasegroup may have been different in 3.8, so you would have to change that. Other than that, you'd just have to change the html you are outputting as <li> wasn't used in 3.8 either. However, I've never tried it on my 3.8 board, so I can't say for sure.

voglermc 04 Nov 2010 12:10

<a href="album.php?{vb:raw session.sessionurl}u={vb:raw post.userid}" title="View {vb:raw post.username}'s Album" rel="nofollow">View {vb:raw post.username}'s Album</a>

Lynne 04 Nov 2010 14:40

You don't need user profile fields to link to album pages (unless you are doing something different?). I'm sure there is a mod or a thread about what you want to do if you are talking about just a plain link that has nothing to do with profile fields.

voglermc 04 Nov 2010 15:02


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Lynne 04 Nov 2010 15:29

Then you should post in the main forums about it, not in some random article about the profile fields.

Black Tiger 30 Nov 2010 20:32

Looks very interesting. You told me this was possible to make compatible for v3.8.x by changing some html code.

Could you or somebody else tell me what exactly to change? I can read a bit of php, but don't know what to do with it, so I would really need a "look for this and replace with that" solution. It has no hurry though.;)

Thanks in advance!

Lynne 30 Nov 2010 22:03

Did you see this for 3.8? How To Add Custom Profile Field Information To The Postbit

The only thing I think she doesn't cover is doing it all via pluginand it isn't much different at all for 3.8.

Plugin 1
hook location - init_startup
Title - Add User Profile Fields to Postbit Templates - 1
Plugin is Active - Yes
Plugin PHP Code -

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Plugin 2
hook location - showthread_postbit_create
Title - Add User Profile Fields to Postbit Templates - 2
Plugin is Active - Yes
Plugin PHP Code -


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Plugin 3
hook location - postbit_display_complete
Title - Add User Profile Fields to Postbit Templates - 3
Plugin is Active - Yes
Plugin PHP Code -

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Black Tiger 30 Nov 2010 22:16

Yep I have seen that, but she left out the Multiple Selection Menus (like in my post about the comma at vbulletin.com yesterday) and that is just what we needed. That part seems covered now in plugin 3 if I understand everything correctly.

Thank you very much for your time explaining it, we are going to try it.

Lynne 30 Nov 2010 23:06

You need to do plugin 1, 2, and 3, not just 3.

Black Tiger 30 Nov 2010 23:20

Yep, I understood, but thank you for making sure, because I see in my reply I was not clear about me understanding that we needed all 3.;)

Bundle 12 Dec 2010 16:17

Is there a way to make this only display if the user has filled in the profile field? e.g. if I tried to make a custom profile field about favourite food, is there a way to stop "Favourite Food: " appearing if the field is blank?

Cheers.

Lynne 12 Dec 2010 19:55

The if condition around it should make it so it doesn't show if it doesn't exist.

sulasno 09 Jan 2011 00:15

thanks for the link to this article

definitely a keeper

stl7997 11 Jan 2011 03:53

1 Attachment(s)
Thank you so much for this article! I was wondering where I need to add a break (see picture) to the code in the template. I would like a break to be done after the 'AE Assignments:' so that everything appears on the line below it.

Thanks in advance!

Lynne 11 Jan 2011 04:02

Quote:

Originally Posted by stl7997 (Post 2147374)
Thank you so much for this article! I was wondering where I need to add a break (see picture) to the code in the template. I would like a break to be done after the 'AE Assignments:' so that everything appears on the line below it.

Thanks in advance!

Can't you just add a <br /> where you want a break?

stl7997 11 Jan 2011 10:32

Quote:

Originally Posted by Lynne (Post 2147377)
Can't you just add a <br /> where you want a break?

Yes that is exactly what I want to do, however I'm a complete noob to PHP. I've tried adding the <br /> in different places to the code but cannot get the desired results.

Where would I add the <br /> in this code? Or is this even the right place to place it?

Sorry for such rookie questions :o


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Lynne 11 Jan 2011 21:16

Put it right after the </dt> and before the <dd> for the field you are adding.

stl7997 12 Jan 2011 03:20

Quote:

Originally Posted by Lynne (Post 2147698)
Put it right after the </dt> and before the <dd> for the field you are adding.

:up::D

Thanks Lynne!

Sarcoth 20 Jan 2011 02:28

Can we set this up so only certain users can see postbit addon?

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

I can't seem to get that part to work. Thanks.

Lynne 20 Jan 2011 04:36

It could be you need to globalize $vbulletin if you are using that variable.

Sarcoth 20 Jan 2011 04:59

Quote:

Originally Posted by Sarcoth (Post 2151782)
Can we set this up so only certain users can see postbit addon?

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

I can't seem to get that part to work. Thanks.

Quote:

Originally Posted by Lynne (Post 2151812)
It could be you need to globalize $vbulletin if you are using that variable.

Thanks Lynne. I know I had tried that earlier and thought it did not work. Going over my notes I see I used "$global $vbulletin;". I needed to leave out the first $ to fix the problem.

I thought globalizing it could be a security risk in some cases. Is there a problem doing that in this plugin?

Thank you again for the help on that. Now I can go to sleep. :)

Special Pages 13 Mar 2011 21:55

Very good Lynne. Keep up the good work!

mikem164 18 Mar 2011 17:28

Just did this and it turned out phenomenal! A big THANKS!

ExciterNL 08 May 2011 09:19

Thanks

Booyakan 30 May 2011 17:47

Thanks for this!

Also, I have one question...Let's say I use this in my template..


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Is there anyway to still show it to guests? It disappears on me when I log out. Same holds true for using the plugin method.

Lynne 30 May 2011 18:07

If the field is private (this has to do with your options when setting up the user profile field), then it won't show.

Booyakan 30 May 2011 18:52

Quote:

Originally Posted by Lynne (Post 2201767)
If the field is private (this has to do with your options when setting up the user profile field), then it won't show.

Thanks Lynne, that's what it was.

Killeglass 31 May 2011 16:58

Hello

I am trying to add this directly under the username


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

when I do I get it formatted as


My Field
fieldx


where I would like


My Field fieldx


Any suggestions greatly appreciated


:)

Lynne 31 May 2011 17:20

Can we get a link to see this?

Killeglass 31 May 2011 17:31

Quote:

Originally Posted by Lynne (Post 2202125)
Can we get a link to see this?

Thank you Lynne!!


http://www.scikotics.com/forums


Tim :)

EDIT

here is how I have it installed


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Lynne 31 May 2011 17:40

You need to put it under the userinfo_extra div. Or, put it in it's own div with that class in order to get it layed out correctly.

Killeglass 31 May 2011 17:52

Thank you again Lynne.

Unfortunately I am a bit old and senile LOL

What would the div class be? just guessing here.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Would really like to keep this field up top if possible


Tim :)


EDIT


<dl class="userinfo_extra">

I added another instance and used that to achieve whats needed. I hope no advewrse reactions from using it

Thanks again!!!

Tim :)

8thos 23 Jun 2011 23:51

Cool post.

steve-iv 03 Jul 2011 10:11

Hi guys,

just have a question regarding to display a phrase in my profile field

Let's say i created field9 -> and a language dependend title in field9_title.

Now I edited the postbitlegacy template:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

The problem is, post.field9 is working. Now I want to display the content of the phrase variable called field9_title.

But why is vb:rawphrase not working with field9_title? And what can I do to get it working?

And why is vbphrase not working?

Thanks!

Lynne 03 Jul 2011 17:08

You need to create a plugin to add that phrasegroup to the page. The plugin is shown in the first post.

(Sorry, I'm stuck on dialup right now and not going to go look it up and post it again.)

Nerror 12 Jul 2011 07:10

This is great and just what I was looking for, thanks. :)

One question though, how do I add commas for the multi-selection fields?

I used method 1 and have this code, which works:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

and I tried modifying the code from here to vBulletin 4.x but I am not a coder at all, so adding commas didn't work. :p

Any help much appreciated!

kdog316 10 Dec 2011 06:42

works great but is there a reason if you see in the second post it doesnt show the label for the fields after making a post until I refresh the page. Also announcements never show the labels.

https://www.vbulletin.org/forum/external/2011/12/44.jpg

I went with the more advanced method of inserting this stuff

Ramsesx 19 Jan 2012 09:25

A nice tutorial Lynne, thanks.

michelle86 11 Mar 2012 19:59

Thank you thank you thank you! 5 stars!

EasyEazy 01 Apr 2012 03:26

Great work

Thanks

michaelbang 16 Apr 2012 15:22

I'm struggeling to get my new profilefield right under the username. I've read the previous post about it, but still can't figure out where to your code <vb:if condition="$post['fieldx']"><dt>My FieldX</dt> <dd>{vb:raw post.fieldx}</dd></vb:if>.

Is it in postbit or postbit legacy? And exactly where do I put it? I've tried several places, with no succes.

Thanks a million. :)

Lynne 16 Apr 2012 16:32

Do you have your userinfo on top of the post (postbit) or on the left side of the post (postbit_legacy)? That determines which template to edit.

[email protected] 08 Jun 2012 15:16

There's a way to use profile fields also in other pages like cms articles?

Lynne 08 Jun 2012 16:34

Quote:

Originally Posted by [email protected] (Post 2337748)
There's a way to use profile fields also in other pages like cms articles?

I'm sure there is, but this article is not about that, it is about using them in the postbit template.

Cognitio 09 Jul 2012 22:08

I've set this up using the advanced method but when it displays I only get the binary number and not the array of choices selected... what am I doing wrong?

Lynne 10 Jul 2012 00:47

Quote:

Originally Posted by Cognitio (Post 2346489)
I've set this up using the advanced method but when it displays I only get the binary number and not the array of choices selected... what am I doing wrong?

I don't know. How about a screen shot of your admincp profile field set up and the exact code/hook for your plugin.

Cognitio 12 Jul 2012 02:02

2 Attachment(s)
I actually altered this into another mod - Profile Intro. The mod adds a memberprofile header that displays custom profile fields defined from the usercp. The mod itself displays input and textarea fields fine, but when it comes to multi_select fields they only display the binary code. I searched through and found this article and attempted to alter it into the Profile Intro mod, the basic function that would require a template modification every time I change a custom field works fine, but I rather have the more advanced option work for ease of use.

Here's the template code I used:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

and here's the plugins code I used (profileintro_typefield is defined as the profilefieldid already):

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Attached are two screen shots, the first is of the display results of the Profile Intro mod within the member.php, and the second screen shot is of the admincp of the customfields as requested. As seen in the first screen shot, the array is correctly shown in the 'About Me' section (which I couldn't find the coding on what to copy to project in the mod), but in the Profile Intro mod it's the binary code and the text I supplied within the coding to define each multi_select option.

Cognitio 02 Aug 2012 15:59

I'm just going to assume I'm being ignored...

TheSupportForum 09 Sep 2012 09:49

hi need help converting this into a plugin for postbit_legacy for the following template hook

$template_hook['postbit_userinfo_right_after_posts']



Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Lynne 09 Sep 2012 15:55

Did you try converting it using this as an example?

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


omega79 25 Sep 2012 10:45

is there any plugin to download to just simply change it without adding code to some templates?

Lynne 25 Sep 2012 15:37

Quote:

Originally Posted by omega79 (Post 2368372)
is there any plugin to download to just simply change it without adding code to some templates?

Under the More Advanced section of my post, I posted the plugin codes. I cannot write a plugin for you to download since you need to enter the fieldid.

TheSupportForum 25 Sep 2012 19:57

Quote:

Originally Posted by Lynne (Post 2364015)
Did you try converting it using this as an example?

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Lynee i always have issues inserting hyperlinks

i want to do something like this



Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Lynne 25 Sep 2012 21:49

You need to use the <a> tag for links - http://www.w3schools.com/tags/tag_a.asp and please use double-quotes in the tag, not single-quotes since the single-quotes are being used in the equation.

omega79 26 Sep 2012 08:38

i am just very new to all this so i have no idea how to do it ...
isn't there a way you can put a form in the pluginconfiguration where the plugin-user could type in or choose the fieldID ?

but well if needed i will probably finishing my community first and after i went live i can look into this again ...

still having headaches over other things in VBB ... have to learn alot ;)

Lynne 26 Sep 2012 17:09

I already have it in a form where all you have to do is change the field id. This is an article, not a modification. If you don't know how to do it, then I suggest you try it out on your test site.

omega79 02 Oct 2012 10:08

okay thank you very much :D
it all looks very complicated if you are new to vbulletin ...
but after some time it gets more simple ...
nice work you done here :D

CentralGarrison 26 Feb 2013 14:39

I'm sorry if this is inappropriate to ask here, but reading through this guide it looks like the same method could be used to put custom profile fields into the user's signature. Which templates would I need to edit to force a custom field to always be displayed in a user's signature?

EDIT: Nevermind, please disregard. I found what I needed in the postbit_legacy template! Thank you!

Mysterious Ride 23 Apr 2013 16:13

Quote:

Originally Posted by Lynne (Post 2097602)
Method 2 - Using a template_hook
I have always found it easier to just use the existing $template_hooks in the template and write a plugin to add these. In this case, there is a $template_hook right where we want it, after the user post count:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

So, we would create a plugin with these specifications:
hook location - postbit_display_complete
Title - Add User Profile Fields to Postbit Templates
Plugin is Active - Yes
Plugin PHP Code -

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Change "fieldx" to your actual field name and the green field to whatever you want. Again, notice the html I used is similar to the html used for the text above me new field. Whichever template_hook you use, you should look at the template to see what sort of html is being used around the hook so that you may use similar, proper html also.

I tried to read on how to make this a hyperlink from what others asked, but I got confused. This is the method that you posted that I want to use and what's going to be placed into the profile field is a link to profile post that the member posted for a character. What I trying to get it to look like is this:

Join Date:
Posts:
Character Profile

Even if its the whole Character Profile is the hyperlink that will take member directly to the character profile will work. I believe you said that I would have to use the <a> tag, but I'm not sure how to insert it into the code you already have.

Lynne 23 Apr 2013 16:54

Something like:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

I haven't tested it, but I think it should work.

Mysterious Ride 24 Apr 2013 09:20

That didn't work, I got this error at the top of my board. I tried just doing the regular method two you have posted, but the profile field didn't show up under the post count either.

Lynne 24 Apr 2013 17:20

And what was the error? And what was the *exact* code you entered into the plugin?

Mysterious Ride 25 Apr 2013 02:01

1 Attachment(s)
Sorry, I tried it again and it worked perfectly. I must have not posted something right. I got the error because I left out the:

if ($post['fieldx'])
{

I thought I added it when I tried a second time, but I didn't get an error message nor did anything show up. But here's the completed code for Method 2 that works perfectly:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

The My Link can be anything anyone what's it to be.

I also adjusted the code so that it fits Method 1 and I tested it and it works great to. It still goes in the same place you said.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

I included an attachment to show the end result.

kiddo 22 Aug 2013 19:22

1 Attachment(s)
So I copied the same code from Location to use for other custom profile fields. When I did this, it showed up, but the name didn't as you can see in the image below. Any help??

The custom profile field's name is PSN so for the code

{vb:rawphrase} I put {vb:rawphrase PSN}\



EDIT: FIXED IT! I just completely removed the vb:rawphrase and simply added PSN to the "MyField" part and it worked!

afmarko99 15 Feb 2014 16:15

Thank you very much Lynne

akxt660 04 Apr 2014 00:58

I want to show images in postbit, related to the selected options by the user in the Multiple Choice Menu.

The below code works just in "Single Selection Menu:

<vb:if condition="$post['fieldX']"> <img src="{vb:raw post.fieldX}.png" /> </ a> </ vb: if>

But how do I work on Multiple Choice Menus?

In the image below you can view the images, but it performed with the Single Choice Menus:

https://www.vbulletin.org/forum/external/2014/04/48.jpg

In this case the user should select four options in Multiple Choice Menu.
These images refer to flags that users rescued

ozzy47 04 Apr 2014 01:08

Did you follow all the instructions in the first post?

For Multiple-Selection Menu and Multiple-Selection Checkbox

It is a bit more complicated for these two types of selections since the options selected are stored as a binary number. If you just display the field using the method above, you will get a number, not a list of options selected. So, in order to use these types of fields, you will have to use the method below. Here is a thead that will explain the binary scheme - http://www.vbulletin.com/forum/showt...To-The-Postbit

Method 1
- Modifying the Template
Open the template and find the area you want to add it to. For instance, to add it right after the user post count, find this:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

And then add this underneath (this is assuming the field has 5 options):


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Change "fieldx" to your actual field name and the green field to whatever you want. Notice the html I used is similar to the html used for the text above me new field.

akxt660 04 Apr 2014 01:54

Yes. All ok now!

I found a problem here:
<vb:if condition="$post['fieldx']"><dt>My FieldX</dt><dd>
<vb:if condition="$post['fieldx'] & 1">Your 1rst option</vb:if>
<vb:if condition="$post['fieldx'] & 2">Your 2nd option</vb:if>

correct is:
<vb:if condition="$post['fieldx']"><dt>My FieldX</dt><dd> </vb:if>
<vb:if condition="$post['fieldx'] & 1">Your 1rst option</vb:if>
<vb:if condition="$post['fieldx'] & 2">Your 2nd option</vb:if>

I get string error because of this small problem!

ozzy47 04 Apr 2014 01:56

Excellent, glad you got it sorted. :)

Protonus 29 Apr 2014 02:12

TL;DR - how can I display a multi line textbox custom profile field, with line breaks preserved, in the postbit?

I've got a Multi Line Text Box, custom profile field, that I would like to display in my legacy postbit. I'm using this code from the OP:

<vb:if condition="$post['fieldx']"><dt>My FieldX</dt> <dd>{vb:raw post.fieldx}</dd></vb:if>

And it works great! But it doesn't respect line breaks, that users entered into this profile field, which makes it look really weird when you have more than one item listed.

I found a post mentioning this:
Quote:


Multiple Line Text Boxes

While I don't recommend displaying these in the postbit as they can contain a large amount of information, they are done in the exact same way as the single line text box.

Note: The text entered will display all on one line, not in multiple lines as added to the text box and displayed in the profile page.
But... no mention on how to fix it? Thanks in advance!

Lynne 29 Apr 2014 04:00

You'd have to look at the array and put line feeds between the items. I haven't ever needed to look into this, so I can't offer a solution to you.

kh99 30 Apr 2014 10:09

You might try:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


but I haven't tried it myself.

Protonus 30 Apr 2014 21:13

Quote:

Originally Posted by kh99 (Post 2495471)
You might try:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

but I haven't tried it myself.

Thank you for the suggestion! It DOES preserve the line breaks now, however, it also doesn't word wrap now, which means it allows long lines to spill into the post area from the postbit. Doh!

So, close, but I had to roll back due to the spill over issue.

DreadsUK 30 Apr 2014 21:57

oh man im so shit at this lol

ok, so vB4.2.2 and editing in postbit template

The field i've created is gender with 2 options male or female.

http://s9.postimg.org/5qp9yvmf3/Scre...t_06_38_27.png

Here is the code i've got in there. Its not working and i bet one of you guys will take 1 look and it will be so obvious lol

https://www.vbulletin.org/forum/external/2014/04/1.png

Lynne 01 May 2014 18:05

It's "field7", not "Field7".

DreadsUK 02 May 2014 19:05

<vb:if condition="$post['field7']"><dt>Gender</dt> <dd>{vb:raw post.field7}</dd></vb:if>

Not working

Mark.B 02 May 2014 19:22

Take off the conditionals so you just have this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Does anything show up now?

This is really a test that you are editing the correct template in the correct style, since now, even if your field id was wrong you should at least see "Gender" in the postbit.

Lynne 02 May 2014 19:27

Are you sure the poster has even set the gender in their profile?

DreadsUK 02 May 2014 19:34

Quote:

Originally Posted by Lynne (Post 2495885)
Are you sure the poster has even set the gender in their profile?

Yea, the poster is me hehe. good question tho :p

--------------- Added 02 May 2014 at 19:38 ---------------

AHHHH, i was editing

'postbit' not 'postbit_legacy'

Mark.B 02 May 2014 20:13

Quote:

Originally Posted by Mark.B (Post 2495883)
This is really a test that you are editing the correct template

Quote:

Originally Posted by DreadsUK (Post 2495889)
AHHHH, i was editing

'postbit' not 'postbit_legacy'

The old ones are the best. ;)

jagtpf 23 Jun 2015 13:13

Have been trying to use method 2 ...

This works >>>>

if ($post[field40])
{
$ImagePath = vB_Template_Runtime::fetchStyleVar('imgdir_misc').'/critique/nocritique.png';
$template_hook['postbit_userinfo_right_after_posts'] .=
'<br /><dt>Critique Level</dt><br /> <dd><img src="' . $ImagePath . '"/></dd>';
}

Yielding both Critique Level: and an image.


Adding conditional doesn't, if there is just one conditional I get Critique Level: and a broken image link; the only difference is the "& 4" - If I use with three conditionals I get 3 * Critique Level: s and 3 broken image links .... It also seems as though it is ignoring the "if" statement because it shows on every profile.>>>>

if ($post[field40])
{
if ($post[field40] & 4)
$ImagePath = vB_Template_Runtime::fetchStyleVar('imgdir_misc').'/critique/nocritique.png';
$template_hook['postbit_userinfo_right_after_posts'] .=
'<br /><dt>Critique Level</dt><br /> <dd><img src="' . $ImagePath . '"/></dd>';
}

I can hazard a guess that using three conditionals there could be a confusion over $ImagePath, but surely it should work with just the one condition ?

I'm missing something rather simple I think ?!

Lynne 23 Jun 2015 18:52

You need some parenthesis after your second condition (why are you using a second one anyway?).


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


jagtpf 25 Jun 2015 09:08

Not too sure what you mean by "why am I using a second condition...."

I'm following your method 2 :

Quote:

if ($post['fieldx'])
{
$template_hook['postbit_userinfo_right_after_posts'] .= '<dt>My FieldX</dt> <dd>';

if ($post['fieldx'] & 1) $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 1rst option';
if ($post['fieldx'] & 2) $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 2nd option';
if ($post['fieldx'] & 4) $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 3rd option';
if ($post['fieldx'] & 8) $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 4th option';
if ($post['fieldx'] & 16) $template_hook['postbit_userinfo_right_after_posts'] .= 'Your 5th option';

$template_hook['postbit_userinfo_right_after_posts'] .= '</dd>';
}
but for 3 conditions. But even ignoring the conditional, I can't get a true result from conditional statement for any of ; ($post[field40] & 1), ($post[field40] & 2) or ($post[field40] & 4), whilst I can from ($post[field]).

[field40] contains 3 radio buttons.

Looks like I need to keep hammering at it ....

Lynne 25 Jun 2015 19:26

Since you didn't use the code tags, it looked like your code was not all on one-line, which it needs to be if you don't use the parenthesis.

You don't use that code for a radio button though. That code is for Multiple-Selection Menu and Multiple-Selection Checkbox profile fields. You need to use the code for For Single-Line Text Box, Multiple-Line Text Box, Single-Selection Radio Buttons, and Single-Selection Menu profile fields.

ProfC 09 Jul 2015 22:44

Hi Lynne,

Is it possible to display a different image on the postbit depending on the option chosen on a single-selection menu?

Example: "What is your favourite colour?"
Red
Blue
Green
Orange

I've used method one but am suspecting that method two may actually be more suitable for this task.

Thank you in advance,

ProfC.

Lynne 10 Jul 2015 17:01

You could use either template edits or a plugin to do what you want. In the examples I show, just replace 'Your 1rst option' with '<img src="image.png" alt="Red Image" height="xx" width="yy">'

ProfC 10 Jul 2015 17:25

Quote:

Originally Posted by Lynne (Post 2549860)
You could use either template edits or a plugin to do what you want. In the examples I show, just replace 'Your 1rst option' with '<img src="image.png" alt="Red Image" height="xx" width="yy">'

Thank you! I'll take a look and see what I get. :)

friendlymela 21 Jul 2015 17:28

Good advices thanks for share this

ProfC 24 Jul 2015 14:05

I'm having a bit of trouble somewhere with this. I decided to go the plugin method for multiple selection fields, as it seemed to offer the means to set different things to display based on the option selected. Unfortunately, I haven't been able to get any further than it displaying "house memberships" (the field name) on the postbit.

I'm not sure whether I've even used the right method or not but the "single selection menu" method didn't appear to have the options to display a different result based on what was selected in the profile menu.

Would it be possible for someone to tell me where I've gone wrong? (I get the sensation I'll be asking this a lot -sigh-) Thank you in advance :)

Plugin code:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


MarkFL 24 Jul 2015 14:22

You want to use "==" instead of "&" in your conditionals. However, might I suggest using a switch statement instead?


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


ProfC 24 Jul 2015 15:48

Thank you; although it appears I'm getting the same result using your version as I am with the one I added following the article.

MarkFL 24 Jul 2015 16:46

What hook location are you using?

ProfC 24 Jul 2015 16:52

"postbit_display_complete" as mentioned in the article.


All times are GMT. The time now is 11:11.

Powered by vBulletin® Version 3.8.14
Copyright © 2021, MH Sub I, LLC dba vBulletin. All Rights Reserved. vBulletin® is a registered trademark of MH Sub I, LLC
Copyright ©2001 - , vbulletin.org. All rights reserved.