Zeta Components Manual :: Docs For Class ezcTemplateLocation
Template::ezcTemplateLocation
Interface ezcTemplateLocation
Interface for classes implementing a dynamic template location.
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:
- Hello word!
- {include dynloc("my_template.ezt")}
With the following custom function definition:
- class DynLocCF implements ezcTemplateCustomFunction
- {
- public static function getCustomFunctionDefinition( $name )
- {
- if ( $name === "dynloc" )
- {
- $def->class = __CLASS__;
- $def->method = "dynloc";
- $def->sendTemplateObject = true;
- return $def;
- }
- return false;
- }
- public static function dynloc($templateObj, $name)
- {
- return new DynamicLocation($templateObj, $name);
- }
- }
The dynloc() method returns a new DynamicLocation object. A simple implementation of the ezcTemplateLocationInterface is shown below:
- class DynamicLocation implements ezcTemplateLocationInterface
- {
- protected $templatePath;
- protected $templateName;
- public function __construct( $templateObj, $templateName)
- {
- $this->templateName = $templateName;
- $this->templatePath = $templateObj->usedConfiguration->templatePath;
- }
- public function getPath()
- {
- $loc = $this->templatePath ."/". $this->templateName;
- {
- $loc = "/fallback/" . $this->templateName;
- }
- return $loc;
- }
- }
The template will first try to use the original template. If that template does not exist, it uses the fallback template.
Source for this file: /Template/src/interfaces/location.php
Version: | //autogen// |
Method Summary
public string |
getPath(
)
Implement this method to return the path to the template source. |
Methods
getPath
Implement this method to return the path to the template source.
The original template name is set with any other method.