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

Lack of Interest Ability to pass additional variables to CSS templates

Discussion in 'Closed Suggestions' started by Jake B., Mar 13, 2015.

  1. Jake B.

    Jake B. Well-Known Member

    Currently (at least from what I can tell), you can't pass additional variables to css templates using template_create like you can for normal templates, and XenForo_CssOutput has the following contents:

    public function renderCss()
            $cacheId = 'xfCssCache_' . sha1(
                'style=' . $this->_styleId .
                'css=' . serialize($this->_cssRequested) .
                'd=' . $this->_inputModifiedDate .
                'dir=' . $this->_textDirection .
                'minify=' . XenForo_Application::get('options')->minifyCss)
                . (XenForo_Application::debugMode() ? 'debug' : '');
            if ($cacheObject = XenForo_Application::getCache())
                if ($cacheCss = $cacheObject->load($cacheId, true))
                    return $cacheCss . "\n/* CSS returned from cache. */";
            if (XenForo_Application::isRegistered('bbCode'))
                $bbCodeCache = XenForo_Application::get('bbCode');
                $bbCodeCache = XenForo_Model::create('XenForo_Model_BbCode')->getBbCodeCache();
            $params = array(
                'displayStyles' => $this->_displayStyles,
                'smilieSprites' => $this->_smilieSprites,
                'customBbCodes' => !empty($bbCodeCache['bbCodes']) ? $bbCodeCache['bbCodes'] : array(),
                'xenOptions' => XenForo_Application::get('options')->getOptions(),
                'dir' => $this->_textDirection,
                'pageIsRtl' => ($this->_textDirection == 'RTL')
            $templates = array();
            foreach ($this->_cssRequested AS $cssName)
                $cssName = trim($cssName);
                if (!$cssName)
                $templateName = $cssName . '.css';
                if (!isset($templates[$templateName]))
                    $templates[$templateName] = new XenForo_Template_Public($templateName, $params);
            $css = self::renderCssFromObjects($templates, XenForo_Application::debugMode());
            $css = self::prepareCssForOutput(
                (XenForo_Application::get('options')->minifyCss && $cacheObject)
            if ($cacheObject)
                $cacheObject->save($css, $cacheId, array(), 86400);
            return $css;
    Just curious if it'd be possible to get some sort of code event, or even have a 'protected function _cssParams()' that returns an array of the parameters so Add-on developers can add additional parameters to it (It of course, would be on the developer to take into account any CSS caching and not use things that change often)


  2. cclaerhout

    cclaerhout Well-Known Member

    No there's no way to extend, but you can trick the system by using a template Helper. I've attached a demo similar of what I'm using for some private addons.
    Here's the single php file: http://pastebin.com/kRGSq6VZ

    In a css template then, just add this for the demo:
    <xen:set var="$blackColor">{xen:helper variable_css, 'getBlackColor'}</xen:set>
    html {
       background-color: {$blackColor} !important;
    <xen:set var="$customProperties" value="{xen:helper variable_css, 'getCustomProperties'}" />
    html {
       <xen:foreach loop="$customProperties" key="$propertyName" value="$propertyValue">
         {$propertyName}: {$propertyValue} !important;
    As you would have understand, to get new variables, just add new methods in the instanciable class.

    Of course there's an alternative solution: go back to the "normal" template and wrap some css codes between the style tag.
    <style type="text/css">

    Attached Files:

    sinucello likes this.

Share This Page