Template: ezcTemplateLocation
[ ]
[ EBNF ] [ Functions ]
[ ]
[ ]
[ ]
[ ]
Interface: ezcTemplateLocation
|
Interface for classes implementing a dynamic template location. [
source]
An object implementing the ezcTemplateLocationInterface can be used as a substitute for the template source in the ezcTemplate::process() method and inside the template {include} block.
Inside a template, a custom function is used to create this location object. The following template source:
1. Hello word!
2. {include dynloc("my_template.ezt")}
With the following custom function definition:
1. class DynLocCF implements ezcTemplateCustomFunction
2. {
3. public static function getCustomFunctionDefinition( $name )
4. {
5. if ( $name === "dynloc" )
6. {
7. $def = new ezcTemplateCustomFunctionDefinition();
8. $def->class = __CLASS__;
9. $def->method = "dynloc";
10. $def->sendTemplateObject = true;
11. return $def;
12. }
13. return false;
14. }
15.
16. public static function dynloc($templateObj, $name)
17. {
18. return new DynamicLocation($templateObj, $name);
19. }
20. }
The dynloc() method returns a new DynamicLocation object. A simple implementation of the ezcTemplateLocationInterface is shown below:
1. class DynamicLocation implements ezcTemplateLocationInterface
2. {
3. protected $templatePath;
4. protected $templateName;
5.
6. public function __construct( $templateObj, $templateName)
7. {
8. $this->templateName = $templateName;
9. $this->templatePath = $templateObj->usedConfiguration->templatePath;
10. }
11.
12. public function getPath()
13. {
14. $loc = $this->templatePath ."/". $this->templateName;
15. if ( !file_exists( $loc ) )
16. {
17. $loc = "/fallback/" . $this->templateName;
18. }
19.
20. return $loc;
21. }
22. }
The template will first try to use the original template. If that template does not exist, it uses the fallback template.
Method Summary
|
public string |
getPath(
)
Implement this method to return the path to the template source. |
Methods
getPath
string getPath(
)
Implement this method to return the path to the template source.
The original template name is set with any other method.
Last updated: Tue, 01 Sep 2009