/**
  * 
  * @param TemplateInterface $template
  * @param array $nameValueMap
  * @return string
  */
 public function renderTemplate(TemplateInterface $template, array $nameValueMap = [])
 {
     try {
         $this->template = $template->withNameValueMap($nameValueMap);
         while (true) {
             $template = $this->template;
             $this->template = null;
             $this->rendered = $template->render($this);
             if ($this->template === null) {
                 break;
             }
         }
         return $this->rendered;
     } finally {
         $this->rendered = null;
         $this->template = null;
     }
 }