drupal_discover_template

Versions
6 – 7
drupal_discover_template($paths, $suggestions, $extension = '.tpl.php')

Determine and return which template file will generate the output.

This helper allows the theme system to pick the template at runtime instead of build time.

See also

template_page_suggestions()

@see template_preprocess_block()

See also

_theme_process_registry()

@see theme()

Parameters

$paths The paths where templates can be found. See _theme_process_registry() 'theme paths' for more information.

$suggestions The possible template names. These are derived from $variables['template_files'] and $variables['template_file], defined by preprocess functions. Each file is checked on every path in the order of precedence defined by theme().

Return value

The filepath to the template that will generate the output. If none is found, then theme() will use the 'template' as set by _theme_process_registry().

Code

includes/theme.inc, line 936

<?php
function drupal_discover_template($paths, $suggestions, $extension = '.tpl.php') {
  global $theme_engine;

  // Remove slashes or null to prevent files from being included from
  // an unexpected location (especially on Windows servers).
  $extension = str_replace(array("/", "\\", "\0"), '', $extension);

  // Loop through all paths and suggestions in FIFO order.
  $suggestions = array_reverse($suggestions);
  $paths = array_reverse($paths);
  foreach ($suggestions as $suggestion) {
    if (!empty($suggestion)) {
      $suggestion = str_replace(array("/", "\\", "\0"), '', $suggestion);
      foreach ($paths as $path) {
        if (file_exists($file = $path . '/' . $suggestion . $extension)) {
          return $file;
        }
      }
    }
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.