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

template_create for css templates?

Discussion in 'XenForo Development Discussions' started by Jake B., Feb 26, 2015.

  1. Jake B.

    Jake B. Well-Known Member

    I'm trying to use template_create to add a couple variables to a css file. However, it appears template_create doesn't run for css templates. Is there any sort of known workaround for this?

    - Jake
     
  2. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    Only the template that are 'called' can be ported into with template_create:
    • xenforo
    • form
    • public
    and other 'required' CSS...​
     
  3. Jake B.

    Jake B. Well-Known Member

    Guess I'll have to put the css into the page_container then. I was digging through XenForo to find where xenOptions was added and I found this in XenForo_CssOutput

    Code:
    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. */";
                }
            }
    
            $this->_prepareForOutput();
    
            if (XenForo_Application::isRegistered('bbCode'))
            {
                $bbCodeCache = XenForo_Application::get('bbCode');
            }
            else
            {
                $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')
            );
    
            var_dump($params);die;
    
            $templates = array();
            foreach ($this->_cssRequested AS $cssName)
            {
                $cssName = trim($cssName);
                if (!$cssName)
                {
                    continue;
                }
    
                $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(
                $css,
                $this->_textDirection,
                (XenForo_Application::get('options')->minifyCss && $cacheObject)
            );
    
            if ($cacheObject)
            {
                $cacheObject->save($css, $cacheId, array(), 86400);
            }
    
            return $css;
        }
    
    But can't really do anything with that without overwriting the entire method though unfortunately :\ Guess I'll just stick the CSS into page_container
     
  4. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    yeah... it would've been awesome if XenForo added a listener to port into the params for CSS...
     

Share This Page