You are here

static function Messaging_Template_Engine::render_elements in Messaging 6.3

Render recursively an array of elements

1 call to Messaging_Template_Engine::render_elements()
Messaging_Template::render in messaging_template/messaging_template.inc
Render all template elements

File

messaging_template/messaging_template.inc, line 154
Base classes for messaging templates

Class

Messaging_Template_Engine
Static template functions that interact with the module API

Code

static function render_elements(&$elements, $method, $language, $objects = array()) {
  $replace = $texts = array();
  foreach ($elements as $key => $element) {
    if (is_object($element)) {
      $needs_replace = $element
        ->needs_replace();
      $value = $element
        ->get_content($method, $language);
    }
    elseif (is_array($element)) {
      $needs_replace = FALSE;
      $value = self::render_elements($element, $method, $language, $objects);
    }
    else {
      $needs_replace = TRUE;
      $value = $element;
    }

    // If needs replace add $texts placeholder to preserve the order
    if ($needs_replace) {
      $replace[$key] = $value;
      $texts[$key] = NULL;
    }
    else {
      $texts[$key] = $value;
    }
  }
  if ($replace) {
    $texts = array_merge($texts, self::text_replace($replace, $objects, $method, $language));
  }
  return $texts;
}