Templates from the File System

Kier

XenForo developer
Staff member
Thought you might like to know that I've just finished up our system to allow you to (optionally) fetch front-end templates from the file system, which means that they can be cached with APC, XCache etc.

The code to do it has always been in XenForo, but it's just tonight that I've put the finishing touches to allow it to be used.

That is all :)
 
Templates from the File System ?????????????????????????????????????
Why this?

Please, help me.
 
Templates from the File System ?
Why this?
Because storing templates in the database means that they have to be rendered using eval(), which cannot be cached. Templates stored in the file system can be rendered using include(), which can be cached.

Don't worry, apart from turning the option on and off, the user experience, including editing the templates, is identical.
 
Excellent. Thanks Kier.

Does this mean we can edit them at the command line too?
You can store data in a database in a few ways, such as through MySQL, or flatfile.

The file system is used to store flatfile. To introduce another caching option.
 
Few weeks back, some one was discussing about WordPress like file system based theme/template system. When I saw the title, I thought it was "that" same thing. :-)
 
No, you have to edit them with the template editor in the ACP, or via WebDAV. Unless you want to edit compiled PHP code.
This statement is leading me to believe that this system doesn't allow for the file-system templates to easily allow placing templates under source control?
 
You can do this already because the phrase,template and some other datawriters have this implemented.

You only need to overwrite them because they check ATM if addon_id == 'XenForo'

PHP:
    */
    protected function _getDevOutputDir()
    {
        if ($this->get('style_id') == 0 && $this->get('addon_id') == 'XenForo')
        {
            return $this->getOption(self::OPTION_DEV_OUTPUT_DIR);
        }
        else
        {
            return '';
        }
    }

I've overwriten this with
PHP:
class Ragtek_DeveloperTools_DataWriter_Template extends XFCP_Ragtek_DeveloperTools_DataWriter_Template
{
        protected function _getDevOutputDir()
    {

        $config = XenForo_Application::get('config');

        if ($this->get('style_id') == 0 && $this->get('addon_id') == $config->development->default_addon)
        {

            return $this->getOption(self::OPTION_DEV_OUTPUT_DIR);
        }
        else
        {
            return '';
        }
    }
}

And in template model
PHP:
class Ragtek_DeveloperTools_Model_Template extends XFCP_Ragtek_DeveloperTools_Model_Template
{

    public function getTemplateDevelopmentDirectory()
    {

        $config = XenForo_Application::get('config');
        if (!$config->debug || !$config->development->default_addon) {
            return '';
        }

        return XenForo_Application::getInstance()->getRootDir()
              . '/' . $config->development->directory . '/file_output/templates';
    }
}

And voila=>
outp.webp

Then (if you want/need it) you need a extrascript to import this stuff and then you'll have a perfect development environment for more devs:)
 
Thought you might like to know that I've just finished up our system to allow you to (optionally) fetch front-end templates from the file system, which means that they can be cached with APC, XCache etc.
Any benefit for those using file system cache? :coffee:
 
Top Bottom