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

Use option in template conditional

SimonV

Well-known member
#1
I have an option that I want to use the output in a template condition, the option is a PHP Callback - Array as seen below:
option.jpg

using this code that I found somewhere here on the forums:

PHP:
<?php

class AddToHomeSceen_Options_UserGroupChooser extends XenForo_Option_UserGroupChooser
{
    public static function renderCheckbox(XenForo_View $view, $fieldPrefix, array $preparedOption, $canEdit)
    {
        return self::_render('option_list_option_checkbox', $view, $fieldPrefix, $preparedOption, $canEdit);
    }
}
Up to this point I'm fine, I have the option as I need it but now I'm stuck in how to utilise this with a template conditional as the output.

Im looking for a simple way to include user groups in a template condition that are set in an addon's options so if there are better ways to do this please do advise me as Im a total newbie when it comes to XenForo addon creation.

EDIT: Actually it might be better to just not include my js file for certain usergroups, I have the file included using addRequiredExternal in my addon Listener file.
 
Last edited:

SimonV

Well-known member
#2
Well I'm slowly learning my way around. In the end a achieved what I wanted all be it a very basic version of what I was trying to do. I used a Text Box - String Field instead with a comma separated value entered and then added my js and css files with the following:

PHP:
$visitor = XenForo_Visitor::getInstance();
$xenoptions = XenForo_Application::get('options');
$user_group_id = $xenoptions->myOptionName;
$user_group_id = explode(',', $user_group_id);

if($visitor->isMemberOf($user_group_id))
{
   $template->addRequiredExternal('css', 'cssTempalte');
   $template->addRequiredExternal('js', 'js/folder/filename.min.js');
}
I now want to use that same option array in a template, how would I go about doing that, any pointers would be great as if I try to use the string value in a conditional only the first value is recognised.