Resources » Chunks » FixInertTags

Chunk example using Javascript in the page template.

The variable tags below are explained elsewhere within the resources documentation. The tags are being displayed instead of being processed by the Etomite parser because blank spaces have been entered between each of the opening and closing tag pair characters. The reason the spaces don't appear is due to the Javascript listed immediately below them. The chunk call for this code is located at the bottom of the page template,  just above the closing body tag, and it looks like: { {FixInertTags} }

[ [cacheable_snippet] ]
[ !non-cacheable_snippet! ]
[ (system_setting_tag) ]
[ *document_object_tag* ]
{ !parseChunk_tag! }

Chunk: FixInertTags
<script type="text/javascript">
<!--

function FixInertTags(t)
{
  /*
  Created: 2008-04-18 by Ralph A. Dahlgren
  Purpose: This function converts inert tags, containing un-natural spaces,
  which have been entered for demonstation purposes, into natural looking
  inert tags by using a blank image.
  */
  
  // check to see if an element id was sent
  if(t != null)
  {
    // if an id was sent, use that element
    var e = document.getElementById(t);
  }
  else
  {
    // if no id was sent, use the body element
    var e = document.getElementsByTagName('body')[0];
  }

  // fetch the element contents
  var s = e.innerHTML;

  // define the blank image to use, with width and height set to zero
  var b = '<img src="manager/media/images/blank.png" style="width:0; height:0;" alt="blank"/>';

  // perform sequential replacements
  s = s.replace(/\[ \!/g, '['+b+'!');
  s = s.replace(/\! \]/g, '!'+b+']');
  s = s.replace(/\[ \[/g, '['+b+'[');
  s = s.replace(/\] \]/g, ']'+b+']');
  s = s.replace(/\{ \{/g, '{'+b+'{');
  s = s.replace(/\} \}/g, '}'+b+'}');
  s = s.replace(/\[ \*/g, '['+b+'*');
  s = s.replace(/\* \]/g, '*'+b+']');
  s = s.replace(/\[ \(/g, '['+b+'(');
  s = s.replace(/\) \]/g, ')'+b+']');
  s = s.replace(/\[ \~/g, '['+b+'~');
  s = s.replace(/\~ \]/g, '~'+b+']');
  s = s.replace(/\{ \!/g, '{'+b+'!');
  s = s.replace(/\! \}/g, '!'+b+'}');
  s = s.replace(/\[ \^/g, '['+b+'^');
  s = s.replace(/\^ \]/g, '^'+b+']');

  // write modified contents back to element
  e.innerHTML = s;
}

// call the fixInertTags function
FixInertTags();

//-->
</script>