Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Custom resource in combination with variable resource name

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Installation and Setup
View previous topic :: View next topic  
Author Message
xilentxage
Smarty Rookie


Joined: 25 Oct 2010
Posts: 15

PostPosted: Sun Feb 12, 2012 5:21 pm    Post subject: Custom resource in combination with variable resource name Reply with quote

Hi again,

Since my upgrade from 2.x to newest version I'm rewriting my custom resource handlers since apparently a lot has changed.

Please consider my code for the resource handler 'Afile'. I use this to find templates from a number of dirs, and to 'glue' multiple template files together.

Code:

#Afile resource------------------------------------------------------------------------------------
class Smarty_Resource_Afile extends Smarty_Resource_Custom {

   #fetch method----------------------------------------------------------------------------------
    protected function fetch($name, &$source, &$mtime){

      #init
      global $_incl;

      #read
      $files = $_incl->lookup($name, true);
      if ( isset($files['self']) ) {
         $source = file_get_contents($files['self']);
         $mtime = filemtime($files['self']);
      }
      else {
         $tpl_source = "";
         $mtime = time();
      }
      if ( isset($files['add']) ) {
         foreach ( $files['add'] as $vfile ) {
            $source .= file_get_contents($vfile);
            if ( filemtime($vfile) > $mtime ) { $mtime = filemtime($file); }
         }
      }

    }


   #fetch timestamp method------------------------------------------------------------------------
    protected function fetchTimestamp($name) {

      #init
      global $_incl;

      #read
      $files = $_incl->lookup($name, true);
      if ( isset($files['self']) ) { $mtime = filemtime($files['self']); }
      else { return time(); }
      if ( isset($files['add']) ) { foreach ( $files['add'] as $vfile ) {  if ( filemtime($vfile) > $mtime ) { $mtime = filemtime($file); }}}

      #return
      return $mtime;

    }
}


The handler works fine on the first 10 templates, but then:

Fatal error: Uncaught exception 'SmartyException' with message 'Unable to read template afile '_stylesheets/contrast_debug.css'' in ***Smarty-3.1.7/libs/sysplugins/smarty_resource_custom.php:80 Stack trace: #0 ***/Smarty-3.1.7/libs/sysplugins/smarty_resource.php(744): Smarty_Resource_Custom->getContent(Object(Smarty_Template_Source)) #1***Smarty-3.1.7/libs/sysplugins/smarty_internal_templatecompilerbase.php(156): Smarty_Template_Source->__get('content') #2 ***Smarty-3.1.7/libs/sysplugins/smarty_internal_template.php(187): Smarty_Internal_TemplateCompilerBase->compileTemplate(Object(Smarty_Internal_Template)) #3 ***Smarty-3.1.7/libs/sysplugins/smarty_internal_templatebase.php(155): Sm in ***Smarty-3.1.7/libs/sysplugins/smarty_resource_custom.php on line 80

I'm sure that the supplied template file is readable though. When I try to debug my handler I notice that, for this template, the method fetchTimestamp() is run, and a valid and correct timestamp is returned. After that the error is thrown, method fetch is not called anymore.

The include of the template file is done fron another template like this:

Code:

/*<![CDATA[[*/

{if isset($_stylesheets)}{foreach from=$_stylesheets item=_filename}

/* ================ {$_filename} ======== */
{include file="afile:$_filename"}
{/foreach}{/if}

/*]]>*/


Any ideas?
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Installation and Setup All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP