XF 2.0 html Widget

Graham Smith

Active member
Am trying to output the contents of one of our Custom User Fields within an html widget.

I'm using this line, but it outputs nothing.

Any ideas?

{$user.customFields.••id••of••my••field••.value}
 
What is $user supposed to represent? If it's supposed to represent the currently logged in user then you'd need to use $xf.visitor.

If you're displaying the widget in a template where the $user variable is usually available (such as a specific member's profile) then the user context might be available, in which case you'd use: $context.user.
 
Thanks Chris

I've tried this…

Code:
<xf:if is="{{$xf.visitor.isMemberOf(13)}}">
Your membership number is {$xf.visitor.customFields.your_voc_membership_numbe.value}. You are registered and recognised as a VOC Club Member. You have full access to all features of this Club website.</p>
</xf:if>


The usergroup I want to display this to is obviously 13. The Customer Userfield ID is "your_voc_membership_numbe"

All that I get displayed when I visit the page is

"Your membership number is . You are registered and recognised as a VOC Club Member. You have full access to all features of this Club website.

The custom field doesn't display.

What am I missing?

Graham.

PS - have also tried
Code:
$xf.visitor.
 
Oh yeah, there's of course a slight syntax change since XF1. Custom fields are available from the "Profile" relation, so this should work:
HTML:
<xf:if is="$xf.visitor.isMemberOf(13)">
    <p>Your membership number is {$xf.visitor.Profile.custom_fields.your_voc_membership_numbe}. You are registered and recognised as a VOC Club Member. You have full access to all features of this Club website.</p>
</xf:if>
 
Chris - you are a genius - that worked brilliantly thanks VERY much.

As an aside, I'd really love to learn more about writing this sort of stuff.

Can you suggest a website/book that's suitable for a complete beginner like me?!
 
It depends what you want to learn, exactly.

HTML and CSS is a good place to start if you know very little. There's interactive courses on places like https://www.codecademy.com/ which are useful. For something a bit more substantial, I'd recommend https://udemy.com.

If you're just interested in XF stuff, and maybe interested in developing XF add-ons and seeing how the code works, then the developer documentation is here:

https://xenforo.com/xf2-docs/dev/
 
That’s really useful Chris.

Thanks very much - it's really appreciated.


I've also tried including the location field, but can't work out how to 'describe' it. I've tried many variations, but can't seem to stumble across the right one…

This is the one I'm trying, but I don't think it's right…

Code:
{$xf.user.visitor.location}


Code:
<xf:if is="$xf.visitor.isMemberOf(13)">
    <p>{$xf.visitor.Profile.custom_fields.forename} {$xf.visitor.Profile.custom_fields.surname} - your online forum username is "{$xf.visitor.username}", the location you have chosen to share with other forum users is "{$xf.user.visitor.location}"  and your VOC membership number is {$xf.visitor.Profile.custom_fields.your_voc_membership_numbe}.
        <br>You are registered and recognised as a VOC Club Member. You have full access to all features of this Club website.</p>
</xf:if>[CODE]
 
You can always dump a variable to see what is in its content. For example, if you dump $xf.visitor,
{{dump($xf.visitor)}}
you will notice, it's not directly attached to $visitor.
 
Top Bottom