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

Templates from the File System

Discussion in 'General XenForo Discussion and Feedback' started by Kier, Oct 16, 2011.

  1. Kier

    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 :)
     
    Jarod, cobra1162, Walter and 28 others like this.
  2. Onimua

    Onimua Well-Known Member

    Ah, was that what that brief moment in downtime was?
     
  3. DSF

    DSF Well-Known Member

    Templates from the File System ?????????????????????????????????????
    Why this?

    Please, help me.
     
  4. Floris

    Floris Guest

    Excellent, this should help bigger sites
     
  5. Marcus

    Marcus Well-Known Member

    That's a huge speed improvement. Thanks!
     
  6. Kier

    Kier XenForo Developer Staff Member

    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.
     
  7. Brogan

    Brogan XenForo Moderator Staff Member

    Is this what the /internal_data/page_cache directory is for?
     
  8. Kier

    Kier XenForo Developer Staff Member

    Nope, that's for something else entirely, that is unlikely to be finished for 1.1. :)
     
  9. CyclingTribe

    CyclingTribe Well-Known Member

    Excellent. Thanks Kier.

    Does this mean we can edit them at the command line too?
     
  10. Kier

    Kier XenForo Developer Staff Member

    No, you have to edit them with the template editor in the ACP, or via WebDAV. Unless you want to edit compiled PHP code.
     
  11. Floris

    Floris Guest

    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.
     
  12. CyclingTribe

    CyclingTribe Well-Known Member

    Ah, okey dokey ... thanks. (y)
     
  13. kkm323

    kkm323 Well-Known Member

    Everything is planned ;):cool:
     
    RvG likes this.
  14. ibnesayeed

    ibnesayeed Well-Known Member

    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. :)
     
  15. Jeremy

    Jeremy XenForo Moderator Staff Member

    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?
     
  16. Kier

    Kier XenForo Developer Staff Member

    We only write out the contents of xf_template_compiled.
     
  17. Jeremy

    Jeremy XenForo Moderator Staff Member

    :( Here's to hoping the possibility of storing uncompiled versions so that we may easily include them in SVN or another source control agent.
     
  18. ragtek

    ragtek Guest

    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') == && $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') == && $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.PNG

    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:)
     
    bambua likes this.
  19. Kevin

    Kevin Well-Known Member

    Any benefit for those using file system cache? :coffee:
     
  20. Marcus

    Marcus Well-Known Member

    Speed. Another benefit is to be able to edit files from external programs.
     

Share This Page