templateContentRaw = $template->getRawContent(); $this->templateFieldNames = $template->getFields(); $this->templateFieldDelimiter = $template->getDelimiter(); $this->viewModelData = $viewModel->getData(); $this->transformer = $transformer; } /** * @param bool $cleanup * @return bool|mixed|string */ public function render($cleanup = true) { if($this->renderedContent) {return $this->renderedContent;} $content = $this->templateContentRaw; foreach($this->viewModelData as $key => &$value) { if(in_array($key,$this->templateFieldNames,false)) { $valueStr = $this->transformer->toString($value); $token = '{' . $this->templateFieldDelimiter . $key . $this->templateFieldDelimiter . '}'; $content = str_replace($token,$valueStr,$content); } } unset($value); if($cleanup) { foreach($this->templateFieldNames as $fieldName) { $token = '{' . $this->templateFieldDelimiter . $fieldName . $this->templateFieldDelimiter . '}'; $content = str_replace($token,'',$content); } } return $content; } }