.

TemplateEngineSimple Class Reference
[View]

Simple template that just includes template file. More...

Inheritance diagram for TemplateEngineSimple:
ITemplateEngine

List of all members.

Public Member Functions

  assign ($name, $value)
  Set a template variable.
  assign_array ($arr)
  Assign array of template variables.
  fetch ($file)
  Renders content.
  retrieve ($name)

Protected Member Functions

  resolve_path ($file)
  Resolve template path.

Protected Attributes

  $vars = array()

Detailed Description

Simple template that just includes template file.

Based upon techniques discussed here: http://www.sitepoint.com/article/beyond-template-engine/

Author:
Gerd Riesselmann

Definition at line 10 of file templateengine.simple.php.


Member Function Documentation

TemplateEngineSimple::assign ( name,
value  
)

Set a template variable.

Parameters:
string  $name
mixed  $value

Implements ITemplateEngine.

Definition at line 24 of file templateengine.simple.php.

00024                                               {
00025                 $this->vars[$name] = $value;
00026         }
TemplateEngineSimple::assign_array ( arr  ) 

Assign array of template variables.

Parameters:
array  $arr Associative array with name as key and value as value

Implements ITemplateEngine.

Definition at line 33 of file templateengine.simple.php.

00033                                            {
00034                 $this->vars = array_merge($this->vars, $arr);
00035         }
TemplateEngineSimple::fetch ( file  ) 

Renders content.

Returns:
string Rendered content

Implements ITemplateEngine.

Definition at line 52 of file templateengine.simple.php.

00052                                      {
00053                 $file = $this->resolve_path($file);
00054                 
00055                 extract($this->vars);
00056                 ob_start(); 
00057                 include($file);  
00058                 $contents = ob_get_contents();
00059                 ob_end_clean();
00060                 
00061                 return $contents;               
00062         }
TemplateEngineSimple::resolve_path ( file  )  [protected]

Resolve template path.

Parameters:
string  $file
Returns:
string

Definition at line 70 of file templateengine.simple.php.

00070                                                {
00071                 return TemplatePathResolver::resolve($file, 'tpl.php');
00072         }
TemplateEngineSimple::retrieve ( name  ) 

Implements ITemplateEngine.

Definition at line 43 of file templateengine.simple.php.

00043                                         {
00044                 return Arr::get_item($this->vars, $name, false);                
00045         }

Member Data Documentation

TemplateEngineSimple::$vars = array() [protected]

Definition at line 16 of file templateengine.simple.php.


The documentation for this class was generated from the following file: