@@ -179,7 +179,7 @@ function getIncludePath(path, options) {
179179 if ( ! includePath && Array . isArray ( views ) ) {
180180 includePath = resolvePaths ( path , views ) ;
181181 }
182- if ( ! includePath ) {
182+ if ( ! includePath && typeof options . includer !== 'function' ) {
183183 throw new Error ( 'Could not find the include file "' +
184184 options . escapeFunction ( path ) + '"' ) ;
185185 }
@@ -307,6 +307,17 @@ function fileLoader(filePath){
307307function includeFile ( path , options ) {
308308 var opts = utils . shallowCopy ( { } , options ) ;
309309 opts . filename = getIncludePath ( path , opts ) ;
310+ if ( typeof options . includer === 'function' ) {
311+ var includerResult = options . includer ( path , opts . filename ) ;
312+ if ( includerResult ) {
313+ if ( includerResult . filename ) {
314+ opts . filename = includerResult . filename ;
315+ }
316+ if ( includerResult . template ) {
317+ return handleCache ( opts , includerResult . template ) ;
318+ }
319+ }
320+ }
310321 return handleCache ( opts ) ;
311322}
312323
@@ -515,6 +526,7 @@ function Template(text, opts) {
515526 options . cache = opts . cache || false ;
516527 options . rmWhitespace = opts . rmWhitespace ;
517528 options . root = opts . root ;
529+ options . includer = opts . includer ;
518530 options . outputFunctionName = opts . outputFunctionName ;
519531 options . localsName = opts . localsName || exports . localsName || _DEFAULT_LOCALS_NAME ;
520532 options . views = opts . views ;
0 commit comments