Codit: Template Tracers for Drupal

codit_tto(__FILE__) or codit_ttc(__FILE__)

Drupal Documentation
This function appears in the Codit Module

One of the confusions with Drupal is knowing where content is coming from, what tpl controls it and where the tpl resides. Place the following template tracer code at the start and end of the output on a tpl and this will never cause confusion again.

Revealing the actual location of the template file is made secure by only revealing the template location if the user has permission to see template tracer output.

Start the template output with the function codit_tto(__FILE__) [Template Tracer Open]

  <?php codit_tto(__FILE__); ?>

End the template output with the function codit_ttc(__FILE__) [Template Tracer Close]

<code>
  <?php codit_ttc(__FILE__); ?>

The output of these functions results in something that looks like this

<!-- <TEMPLATE> /home/thisSite.com/drupal/themes/sometheme/templates/some_template.tpl.php -->
Some rich yummy tempate stuff would be here.
<!-- </TEMPLATE> /home/thisSite.com/drupal/themes/sometheme/templates/some_template.tpl.php -->

Both codit_tto and codit_ttc also support an optional second parameter that will output as an html comment, whatever string, object, or array you pass it immediately following the template tracer comment.
Example:

<?php codit_tto(__FILE__ , 'Help, they are trying to kill me!!'); ?>

Would output:

<!-- <TEMPLATE> /home/somesite.com/drupal/modules/moduleName/templates/some_template.tpl.php -->
<!-- Message: Help, they are trying to kill me!! -->

codit_tto() and codit_ttc() both only output something if the user has the proper permissions.

Functions

<?php
/**
 * Outputs a template tracer opening comment if user has permission to see it.
 *
 * @param string $s_file
 *   The file ' __FILE__' that is calling the tracer.
 *
 * @param mixed $optional_message
 *   Anything you want included in the template tracer output.
 */
function codit_tto($s_file = 'codit_tto() called incorrectly.  Must be codit_tto(__FILE__)', $optional_message = '') {
  print
_codit_tt($s_file, $optional_message, TRUE);
}

/**
 * Outputs a template tracer closing comment if user has permission to see it.
 *
 * @param string $s_file
 *   The file '__FILE__' that is calling the tracer.
 *
 * @param mixed $optional_message
 *   Anything you want included in the template tracer output.
 */
function codit_ttc($s_file = 'codit_ttc() called incorrectly.  Must be codit_ttc(__FILE__)', $optional_message = '') {
  print
_codit_tt($s_file, $optional_message, FALSE);
}

/**
 *  The base function for Template Tracers. Should not be called directly.
 * @param string $s_file
 *   The file '__FILE__' that is calling the tracer.
 *
 * @param mixed $optional_message
 *   Anything to include in the template tracer output.
 *
 * @param bool $open
 *   TRUE if the it is an opening tracer, FALSE if is is closing tracer.
 *
 * @return string
 *   HTML comments to output.
 */
function _codit_tt($s_file = '_codit_tt() called incorrectly.  Must call codit_tto(__FILE__) or codit_ttc(__FILE__)', $optional_message = '', $b_open = TRUE) {
 
$s_tag = ($b_open) ? '<TEMPLATE>' : '</TEMPLATE>';
  if (
user_access('view codit template tracers')) {
    if ((
is_array($optional_message)) || (is_object($optional_message))) {
     
// Means it is a array or opject, so convert it to a pretty string.
     
$optional_message = print_r($optional_message, TRUE);
    }
   
$optional_message = (!empty($optional_message)) ? "<!-- Message: $optional_message -->\n" : '';
    return (
"<!-- $s_tag $s_file -->\n $optional_message");
  }
  return
'';
}
?>

section:

modules: