You wouldn't need to do any additional DOM operations if you just put a replacement identifier in the contact template. 

(Copied from a previous comment)


This should be its own template that is conditionally interpolated and conditionally embedded if `params.renderPhoto` is `true`.

```html
<div id="messages-contact-tmpl" class="hide">
  <!--
  <a class="suggestion"
    data-number="${number}" data-source="contacts" data-name="${name}">
    ${photoHTML}
    <p class="name">${nameHTML}</p>
    <p>
      ${type}${separator}${carrier}${numberHTML}
    </p>
  </a>
  -->
</div>
<div id="messages-contact-photo-tmpl" class="hide">
  <!--
  <aside class="pack-end">
    <img src="${photoURL}">
  </aside>
  -->
</div>
```

Then the code would be:

```js
var li = document.createElement('li');
var data = {
  name: title,
  number: number,
  type: type,
  carrier: carrier,
  separator: separator,
  nameHTML: '',
  numberHTML: ''
};

['name', 'number'].forEach(function(key) {
  if (isSuggestion) {
    data[key + 'HTML'] = data[key].replace(
      regexps[key], function(match) {
        return this.tmpl.highlight.interpolate({
          str: match
        });
      }.bind(this)
    );
  } else {
    data[key + 'HTML'] = Utils.escapeHTML(data[key]);
  }
}, this);

//
// 1. Conditional render the template fragment
//
//    No matter what, this will produce a string value that can be 
//    passed to the contact template.
data.photoHTML = renderPhoto ? 
  this.tmpl.contactPhoto.interpolate({
    photoURL: details.photoURL || ''
  }) : '';

// Interpolate HTML template with data and inject.
// Known "safe" HTML values will not be re-sanitized.
if (isContact) {
  li.innerHTML = this.tmpl.contact.interpolate(data, {
    //
    // 2. Avoid double escaping, we already know that photoHTML
    //    is either safely escaped HTML or an empty string
    // 
    safe: ['nameHTML', 'numberHTML', 'srcAttr', 'photoHTML']
  });
} else {
  li.innerHTML = this.tmpl.number.interpolate(data);
}
ul.appendChild(li);

```

The numbered comments explain the flow