Template Conditionals

Morgan

Active member
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!
 
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.
 
Code:
<xen:if is={$xenOptions.myOptionId}>
random fantastic stuff goes here
</xen:if>
 
oops
Code:
<xen:if is="{$xenOptions.myOptionId}">[/FONT]
random fantastic stuff goes here
</xen:if>
 
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>
 
Boolean isn't for display. It will work. Probably empty on false and 1 on true. Make sure the ID is right.
 
I've checked it multiple times, copied and pasted it to verify that I've done so. It isn't working.
 
{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.
 
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>
 
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.
 
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.
 
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.
 
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?
 
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!
 
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()));
 
Top Bottom