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

Template Conditionals

Discussion in 'XenForo Development Discussions' started by Morgan, Feb 15, 2012.

  1. Morgan

    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!
     
  2. Robbo

    Robbo Well-Known Member

    {$xenOptions.optionID}
     
  3. Morgan

    Morgan Active Member

    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.
     
  4. Robbo

    Robbo Well-Known Member

    Code:
    <xen:if is={$xenOptions.myOptionId}>
    random fantastic stuff goes here
    </xen:if>
     
  5. Morgan

    Morgan Active Member

    Giving me the same syntax error as before:
     
  6. Robbo

    Robbo Well-Known Member

    oops
    Code:
    <xen:if is="{$xenOptions.myOptionId}">[/FONT]
    random fantastic stuff goes here
    </xen:if>
     
  7. Morgan

    Morgan Active Member

    Ah thank you! I had thought I tried quotes but probably not with the curly braces as well.
     
  8. Morgan

    Morgan Active Member

    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>
     
  9. Robbo

    Robbo Well-Known Member

    Boolean isn't for display. It will work. Probably empty on false and 1 on true. Make sure the ID is right.
     
  10. Morgan

    Morgan Active Member

    I've checked it multiple times, copied and pasted it to verify that I've done so. It isn't working.
     
  11. Robbo

    Robbo Well-Known Member

    {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.
     
  12. Morgan

    Morgan Active Member

    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>
     
  13. Robbo

    Robbo Well-Known Member

    The xenOptions is wrong, oops :/ I'll find the real variable.
     
  14. Robbo

    Robbo Well-Known Member

    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.
     
  15. Morgan

    Morgan Active Member

    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.
     
  16. Robbo

    Robbo Well-Known Member

    But <div>{xen:helper dump, $xenOptions}</div> gave NULL?

    Can I see your template code?
     
  17. Morgan

    Morgan Active Member

    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.
     
  18. Robbo

    Robbo Well-Known Member

    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?
     
  19. Morgan

    Morgan Active Member

    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!
     
  20. Robbo

    Robbo Well-Known Member

    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()));
     

Share This Page