what are render arrrays?

here is a link on render arrays

drupal render arrays

Search for: drupal render arrays

a step by step exploration of render arrays

idea of forms

understand drupal forms

Search for: understand drupal forms

good forms introduction on drupal 5

drupal 7 form process flow

Search for: drupal 7 form process flow

form api work flow image

drupal_render

Search for: drupal_render

drupal_render api

a presentation

a little bit more on render array

drupal example render array theme function

Search for: drupal example render array theme function

registering a render array theme hook

Search for: registering a render array theme hook

How can I use a theme template for render arrays in drupal

Search for: How can I use a theme template for render arrays in drupal

Here is an example of how drupal renders html


$items['satyatst1'] = array(
    'page callback' => 'satya_test_render_array',
    'type' => MENU_CALLBACK,
    'access callback' => TRUE,
  );

define a url called /satyatst1 so that this will invoke a function called satya_test_render_array. the goal of this function is to return somethign so that what is returned is painted in the content area of the current theme.

Typically this function could return pure plain html. And that html will then get painted out.

However in this case we will return a data structure. This data structure is called a render array.

I will show you then how we will get an opportunity to render that data.


function satya_test_render_array_2()
{
	$data = array(
	'#theme' => 'satya_test_render_array',
	'd1' => 'hello render arrray',
	);
	return $data;
}

This is saying that this data will be rendered into html using a custom theme function called "theme_satya_test_render_array". Notice that the function name will be prefixed by "theme_".

Also note that this function needs to be registered first before it can be called.

But first let us see what this function looks like.


function theme_satya_test_render_array($element)
{
	dpm($element);
	$data = $element[0];
	return $data['d1'];
}

Any time the data or render array has a property called #theme, that functio pointed by that theme is called by passing the parent array of #theme as the data element.

for some reason the passed in element is an array with a single child pointing to the parent node of the data. that is why I have taken the 0 index element and then access the data


function satya_test_module_theme()
{
	return array(
	   'satya_test_render_array' => array(
	   		'render element' => 'data'));
}

This is the hook that belongs to the module. This hook is responsible for registering any theming functions.

In this case the function name is the key of the array. This function name then indicates that it has one argument which is known as element.(I need to change data to element: note to myself).

Read the hook_theme documentation to see how these arguments are registered.