How to access Custom thread field

Status
Not open for further replies.
Hi everyone.

I know this is probably the wrong section, but since I am evaluating xenForo and am not a licensed member yet I am asking here.

I added a Custom thread field and could see it within the first post of the thread. Now I would like to use it within a html widget in the sidebar. But I did not manage access the variable value. Does anybody know how to access that value?

I tried with {{dump($xf.thread)}} and {{dump($thread)}} but the returned value is always null. But when I use {{dump($xf.visitor.Profile)}} and search for the field value I can see it within the "XFMG\XF\Entity\Thread"-array. So it seems to be somewhere. Any suggestions?

Thank you all.
 
Solution
But only at the 3 given display locations:
Alright, Alright I found a way to access the $thread variable within the HTML widget. lol
Here is the way :D
{{ dump({$context.thread}) }}

I totally forgot the $context, my bad!
And there is a Box around the content which one can not get rid of I suppose?
I think actually, you can.
alxpc7G.png


You use wrapper display HTML and you will get rid of that box. (haven't tested that before)
It's a custom widget "Appearance --> Widgets --> add Widget --> Widget definition = HTML".
So this basically means I cannot use a $thread variable within the widget?
Hmm, widgets are supposed to be loaded in everywhere. so they have to have their own scope.
Imagine if the user is viewing a different page other than thread view, what would be the value of the $thread variable? they are not designed to work that way.
So.. you'll have to create a custom add-on for that. These HTML widgets are not the correct way to access entities. You can only access $xf and there is no link to the current $thread in it.
 
But only at the 3 given display locations:
Alright, Alright I found a way to access the $thread variable within the HTML widget. lol
Here is the way :D
{{ dump({$context.thread}) }}

I totally forgot the $context, my bad!
And there is a Box around the content which one can not get rid of I suppose?
I think actually, you can.
alxpc7G.png


You use wrapper display HTML and you will get rid of that box. (haven't tested that before)
 
Solution
$thread == null means you are in the wrong template, $thread entity has a field named custom_fields so it's supposed to be accessible wherever you have $thread entity

you should be able to call getCustomFields() too. {{ dump($thread.getCustomFields()) }}

and this {{ dump($thread.CustomFields) }}
 
Last edited:
Thank you for the quick response!
But in the widget there is only one textarea called "template". I cannot put the code somewhere else.

Under "Display in positions" I checked "Thread view: Above messages" and "Thread view: Sidebar" for example (both is null).
 
Thank you for the quick response!
But in the widget there is only one textarea called "template". I cannot put the code somewhere else.

Under "Display in positions" I checked "Thread view: Above messages" and "Thread view: Sidebar" for example (both is null).
Which widget are we talking about? if $thread is null, it means that the widget has no access to the $thread variable. it's in a different scope
 
I think it works!

But only at the 3 given display locations:
  • Before message
  • After message
  • Thread status block
And there is a Box around the content which one can not get rid of I suppose?

Just FYI:
We will discuss stocks. So every stock beeing discussed in its own topic. The custom field is the ticker symbol. The ticker symbol can be integrated in a tradingview widget so it looks like this:

shareprice.webp
 
Status
Not open for further replies.
Top Bottom