Example #1
0
 /**
  * Assign another template to a field. This makes it possible to extend an
  * existing template with other templates by assigning new templates to this
  * templates fields.
  * 
  * @param string $field
  * @param Base_Template_Template $template
  * @return $this
  */
 public function assignTemplate($field, Template $template)
 {
     if (!isset($this->fields[$field])) {
         throw new \Exception(sprintf('Field name "%s" does not exist', $field));
     }
     // remove the field from fields array
     unset($this->fields[$field]);
     // add new fields to the active fields array
     $this->fields = array_merge($this->fields, $template->getFields());
     // replace the body content with the new template content
     $this->body = preg_replace('/{{' . $field . '}}/', $template->getBody(), $this->body);
     return $this;
 }