• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Variables in xenOptions?

Chris D

XenForo developer
Staff member
#1
I am working on an add-on with configurable options in the Admin CP.

One of the options needs to have a default value of:

Hey {$visitor.username}!

If I use {$xenOptions.heyUser} in my template, the output is: Hey {$visitor.username}!

I'm looking for it to output: Hey Yorick!
 

Mr. Goodie2Shoes

Well-known member
#2
This is bound to happen because templates are only rendered once, and it only renders {$xenOptions.heyUser} and thats why {$visitor.username} is not rendered ;)
You have to use XenForo's 'hook' system for this...
 

Robbo

Well-known member
#3
I don't even understand the question... or the answer given... what you have written out should just work if you have that option?
 

James

Well-known member
#4
I am working on an add-on with configurable options in the Admin CP.

One of the options needs to have a default value of:

Hey {$visitor.username}!

If I use {$xenOptions.heyUser} in my template, the output is: Hey {$visitor.username}!

I'm looking for it to output: Hey Yorick!
I think I'm following.

You've got a text-field in the Admin CP that contains this text:
"Hey {$visitor.username}!"

and your field ID is heyUser?

So when you use $xenOptions.heyUser - it outputs the text field.

The problem here is that you can't use template syntax inside the text fields - when they're placed in the templates they're treated as normal text. You'll have to use an add-on, as stated above, to achieve what you want.
 

Chris D

XenForo developer
Staff member
#5
It's ok dudes. I knew the reason why it wasn't working, I was more looking for help with a practical solution. But in the end I figured it out.

I've tested this as working. I'm going to explain in the Admin CP options to reference the visitor's username with {user} then I'm going to run a template_post_render and replace {user} with $visitor['username']

:)

Thank you all for the replies.
Options:
heyuser.PNG

End result:
heyuser1.PNG