Difference between drupal_render and render functions in drupal 7

Before we discuss about the differences between drupal_render and render functions in drupal 7, we have to check what hide and show functions does.

NOTE: Every element of an element tree has a #printed flag e.g.{$element ['#printed']}

hide function hides an element form later rendering. It just marked #printed flag with TRUE e.g. [$element ['#printed'] = TRUE;] and the rendered children of the element are cached.

function hide(&$element) {
  $element ['#printed'] = TRUE;
  return $element;
}

show function hides an element form later rendering. It just marked #printed flag with FALSE e.g. [$element ['#printed'] = FALSE;] and the rendered children of the element are cached.

function show(&$element) {
  $element ['#printed'] = FALSE;
  return $element;
}

render function renders an element using drupal_render function. The element is shown with show function before rendering, so it will always be rendered even if hide function had been previously used on it.

In short it always marked TRUE to the #printed flag of an element. that means it always render an element even if we hide that element previously.

drupal_render function renders HTML given a structured array tree. drupal_render function flags each element with a '#printed' status to indicate that the element has been rendered. If we hide an element useing hide function than that element will not be rendered.

Tags