XF 2.2 [PLEASE HELP] Display custom user field on profile

LmaoBoi111

Member
I want users to be able to display a spotify embeded song on their profile, I created a custom user field but I dont know how to replace it in the embed link the song track ID so that it the chosen song by the user can be displayed on their profile. Please someone help me :)
 
Easiest (but not very elegant) solution without coding anything: A custom user field. Go to admin.php?custom-user-fields/add. Choose Rich text box.

Now the user can add a link to a Spotify song. The on-board Spotify Media site BB-Code will transform it to an iframe.
 
Easiest (but not very elegant) solution without coding anything: A custom user field. Go to admin.php?custom-user-fields/add. Choose Rich text box.

Now the user can add a link to a Spotify song. The on-board Spotify Media site BB-Code will transform it to an iframe.
How can I make the widget output the user spotify link from the rich box
 
You can add a HTML widget, that only is displayed on Member view and add this content:

HTML:
{{ bb_code($context.user.Profile.custom_fields.spotify, 'context', $context ) }}

(replace spotify with your chosen field ID; I am not sure how save this is, tough..)
 
You can add a HTML widget, that only is displayed on Member view and add this content:

HTML:
{{ bb_code($context.user.Profile.custom_fields.spotify, 'context', $context ) }}

(replace spotify with your chosen field ID; I am not sure how save this is, tough..)
How can I make it so it only accepts Spotify song links, I dont want people to put other things in there, and also how can I make it display it just if the user inputted something in the custom user field?
 
How can I make it so it only accepts Spotify song links, I dont want people to put other things in there, and also how can I make it display it just if the user inputted something in the custom user field?
Create the field and use the appropriate regex?

Screen Shot 2023-06-25 at 5.40.04 PM.png

I think that if the custom field is not completed... it doesn't show up.
 
Sorry I don't really know how to use a regex, can you give me the regex expression if the links look like this "[link]
To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.
" Also how can I make it display it just if the user input something in the custom user field?

Quote Reply
link is giving errors.... copy the link and either put it in a code box or use the icode /icode bbcode.
Also edited my initial reply.. but I think that if the field is not completed, it does not show up.
As for the regex... it's something I'm still battling to learn for use like this.
 
link is giving errors.... copy the link and either put it in a code box or use the icode /icode bbcode. <edit> now it's embedded but no actual link
Also edited my initial reply.. but I think that if the field is not completed, it does not show up.
Here it is the link in code format:

Code:
https://open.spotify.com/track/6pF5IUal12wqhPY2X8CnJp?si=8d09e344deb548c5
 
Try this regex:
Code:
#^(https:\/\/open.spotify.com\/track\/[^\S]$#/i
It can be improved, but it should work in most cases. It checks for input beginning with https://open.spotify.com/track/ followed by the rest of the URL. The input must not contain any whitespaces, new lines, tabs or similar.

Also how can I make it display it just if the user input something in the custom user field?
try:
HTML:
{{ $context.user.Profile.custom_fields.spotify ? bb_code($context.user.Profile.custom_fields.spotify, 'context', $context ) : '') }}
 
Back
Top Bottom