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

Template Conditionals

Morgan

Active member
#1
So, I've gotten my first Addon mostly finished and all I really have left is just actually using some options I have in my config. So...how do I actually reference say a check box option that I added? I've scoured the development forum, searched and googled but somehow I'm missing this much needed information.
  1. Is there a decent set of documentation for XenForo Addons that I've completely missed?
  2. What would be the best way to reference my specific option?
Thanks!
 

Morgan

Active member
#3
Code:
<xen:if is=$xenOptions.myOptionId>
random fantastic stuff goes here
</xen:if>
Well, this is what I tried...I think I'm still missing the boat however.
 

Morgan

Active member
#8
Well, that isn't working for me. Throwing it into the template like below only just gives me an empty string. I would have expected a boolean value to give me a true/false or 0/1 values instead of a blank string.

Code:
<div>{$xenOptions.myOptionId}</div>
 

Robbo

Well-known member
#11
{xen:helper dump, $xenOptions.yourId} to see what it is going on. You can do just {$xenOptions} too. I hope I haven't missed something obvious, I am running on very little sleep.
 

Morgan

Active member
#12
Hmmm well that definitely got me more information.

Template:
Code:
<div>{xen:helper dump, $xenOptions.myOptionId}</div>
<div>{xen:helper dump, $xenOptions}</div>
Result:
Code:
<div><pre>NULL</pre></div>
<div><pre>NULL</pre></div>
 

Robbo

Well-known member
#14
Nope the option is fine. How is the template created? If it is a hook try adding $template->getParams() as the newly created templates params.
 

Morgan

Active member
#15
That worked as expected. Even did a few foreach loops to get the key values of the first two levels and I see my options exactly as I expect. So the values aren't the issue, but somehow is it how I'm attempting to reference them in the xen template if statment? That's what looks like the problem to me.
 

Morgan

Active member
#17
It's a pretty simple template ;)

Code:
<xen:if is="{$xenOptions.steamDisplayMessageInfo}">
<div>hello world</div>
</xen:if>
<div>{$xenOptions.steamDisplayMessageInfo}</div>
<div>{xen:helper dump, $xenOptions.steamDisplayMessageInfo}</div>
<div>{xen:helper dump, $xenOptions}</div>
<div class="steamprofile" title="{$user.steam_auth_id}"></div>
I do properly see the div and the user's steam_auth_id but none of the options show up.
 

Robbo

Well-known member
#18
You can see an example of it being used in the google_analytics template.
Code:
<xen:if is="{$xenOptions.googleAnalyticsWebPropertyId}">
Do you create that template from a XenForo_Template_Abstract object?
 

Morgan

Active member
#19
I'm not instantiating an object anywhere to be honest. I'm using the addon xml file to specify the defaults it seems then in my Listener I do...

Code:
    public static function templateCreate($templateName, array &$params, XenForo_Template_Abstract $template) {
        switch($templateName) {
            case 'PAGE_CONTAINER':
                $template->preloadTemplate('steam_message_user_info');
                break;
        }
    }
 
    public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template) {
        switch($hookName) {
            case 'message_user_info_text':
                $contents .= $template->create('steam_message_user_info', $hookParams);
                break;
        }
    }
* I took out a few extra templates I was using to make this less overwhelming while reading.

Also...I just barely started figuring out whats going on so its likely I'm not doing this properly!
 

Robbo

Well-known member
#20
I thought $xenOptions was a unique case but it might not be. So try changing this:
Code:
$contents .= $template->create('steam_message_user_info', $hookParams);
To this:
Code:
$contents .= $template->create('steam_message_user_info', array_merge($hookParams, $template->getParams()));