title: How to add hyperlink using templateprocessor (PHPWord Library)
body: <p>I want to replace email variable into a hyperlink using template processor and I have used two way to solved this issue but didn't work and here is our below code for replacing email variable into hyperlink but when I used setValue or setComplexValue function for replacement value then document is corrupted.</p>
  
  <p>We have tried below two scenarios for adding hyperlink but didn't work for us.</p>
  
  <p><strong>1. First Way</strong></p>
  
  <pre><code>$pw = new \PhpOffice\PhpWord\PhpWord();
  $section = $pw-&gt;addSection();
  $textrun = $section-&gt;addTextRun();
  $textrun-&gt;addTextBreak(2);
  $section-&gt;addLink('mailto:demo1@gmail.com?subject=DEMO','demo1@gmail.com', array('color' =&gt; 'FF0000', 'underline' =&gt;
  \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
  $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($pw, 'Word2007');
  $fullXml = $objWriter-&gt;getWriterPart('Document')-&gt;write();
  $templateProcessor-&gt;setValue($var, $this-&gt;getBodyBlock($fullXml));
  </code></pre>
  
  <p><strong>2. Second Way</strong></p>
  
  <pre><code>$pw = new \PhpOffice\PhpWord\PhpWord();
  $section = $pw-&gt;addSection();
  $convertResult = 'demo1@gmail.com';
  
  \PhpOffice\PhpWord\Shared\Html::addHtml($section, $convertResult, false,false);
  $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($pw, 'Word2007');
  $fullXml = $objWriter-&gt;getWriterPart('Document')-&gt;write();
  $templateProcessor-&gt;setValue($var, $this-&gt;getBodyBlock($fullXml)); 
  
  protected function getBodyBlock($string) {
     if (preg_match('%(?i)(?&lt;=&lt;w:body&gt;)[\s|\S]*?(?=&lt;/w:body&gt;)%', $string, $regs)) {
         return $regs[0];
      } else {
         return '';
      }
  }
  </code></pre>
  
  <p>Please help us thank in advance.</p>