This shows you the differences between two versions of the page.
sourceresolver [2010/07/07 23:25] 81.187.95.96 |
sourceresolver [2016/02/10 22:39] (current) 24.114.56.119 |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Source Resolver ===== | + | ====== Source Resolver ====== |
You can create fake filesystems for PHPTAL templates. This lets you load templates //and macros// from any source, e.g. a database. | You can create fake filesystems for PHPTAL templates. This lets you load templates //and macros// from any source, e.g. a database. | ||
Line 19: | Line 19: | ||
if (looks_like_my_path($path)) { | if (looks_like_my_path($path)) { | ||
$source = load_template_from($path); | $source = load_template_from($path); | ||
- | return new PHPTAL_StringSource($path); | + | return new PHPTAL_StringSource($source); |
} | } | ||
} | } | ||
} | } | ||
+ | |||
+ | :!: (in PHPTAL older than 1.2.2 you need ''new PHPTAL_StringSource($source, md5($source))'') | ||
The ''resolve'' function should return instance of ''PHPTAL_Source'' (if it supports the path) or ''NULL''. You can either use ''PHPTAL_StringSource'' class, or implement your own. | The ''resolve'' function should return instance of ''PHPTAL_Source'' (if it supports the path) or ''NULL''. You can either use ''PHPTAL_StringSource'' class, or implement your own. | ||
Line 28: | Line 30: | ||
$phptal->addSourceResolver(new MySourceResolver()); | $phptal->addSourceResolver(new MySourceResolver()); | ||
- | PHPTAL will call ''resolve()'' method whenever it needs to load a template set via ''setTemplate()'' or ''metal:use-macro''. | + | PHPTAL will call ''resolve()'' method whenever it needs to load a template set via ''setTemplate()'' or ''metal:use-macro''. () |
==== Lazy loading of templates ==== | ==== Lazy loading of templates ==== | ||
Line 52: | Line 54: | ||
} | } | ||
- | PHPTAL will call ''getData()'' only when ''getRealPath()'' or ''getLastModifiedTime()'' return different values. | + | PHPTAL will call ''getData()'' only when ''getRealPath()'' or ''getLastModifiedTime()'' return different values.() |