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

container_public_params uncooperative

Discussion in 'XenForo Development Discussions' started by Jake B., Dec 9, 2014.

  1. Jake B.

    Jake B. Well-Known Member

    I'm working on an add-on that will require a variable to be available in all templates, so I tried to use the container_public_params code event with the following:

    public static function containerPublicParams(array &$params, XenForo_Dependencies_Abstract $dependencies)
         $visitor = XenForo_Visitor::getInstance();
         $params['testParam'] = $visitor->hasPermission('test', 'testPermission');
    It is running, and I am able to access the variable inside XenForo_Dependencies_Public::getEffectiveContainerParams however, I cannot use $testParam inside a template.
  2. Chris D

    Chris D XenForo Developer Staff Member

    Container params are only valid in container templates.

    You'll probably find that {$testParam} works fine in PAGE_CONTAINER, for example.

    What you want to do can probably be achieved by listening to template_create.

    XenForo Resource Manager and Media Gallery both do a similar tactic to make some permissions available to any templates, e.g.

    public static function templateCreate($templateName, array &$paramsXenForo_Template_Abstract $template)
        if (
    self::$_hasTemplatePerm === null)
    self::$_hasTemplatePerm XenForo_Visitor::getInstance()->hasPermission('resource''view');

        if (!isset(
    $params['canViewResources'] = self::$_hasTemplatePerm;
    Jake B. likes this.
  3. Jake B.

    Jake B. Well-Known Member

    That worked perfectly. You've saved me once again, thanks!

Share This Page