You are here

function cf_theme_render_variables in Common Functionality 7.2

Same name and namespace in other branches
  1. 7 modules/cf_theme/cf_theme.module \cf_theme_render_variables()

Safely render all variables specified in the $keys array.

Why: Theme *.tpl.php files should not ever have to call generate or perform isset()/empty() checks to prevent errors from happening. All of this work should be done in the template.php. There is not a standard way of doing this such that other modules and themes can hook into. This also allows custom modules to alter themes without having to hack or alter any existing theme that supports these functions.

Parameters

array $variables: The variables array to process.

array $keys: An array of key names to process.

string $subdir: (optional) A string representing a subdirectory inside of the variables parameter.

Related topics

File

modules/cf_theme/cf_theme.module, line 734
Common Functionality - Theme module.

Code

function cf_theme_render_variables(&$variables, $keys, $subdir = NULL) {
  if (is_null($subdir)) {
    foreach ($keys as $key) {
      if (empty($variables[$key])) {
        $variables[$key] = '';
        $variables['cf']['show'][$key] = FALSE;
      }
      else {
        $variables[$key] = render($variables[$key]);
        $variables['cf']['show'][$key] = TRUE;
      }
    }
  }
  else {
    $variables['cf']['show'][$subdir] = array();
    foreach ($keys as $key) {
      if (empty($variables[$subdir][$key])) {
        $variables[$subdir][$key] = '';
        $variables['cf']['show'][$subdir][$key] = FALSE;
      }
      else {
        $variables[$subdir][$key] = render($variables[$subdir][$key]);
        $variables['cf']['show'][$subdir][$key] = TRUE;
      }
    }
  }
}