what are render arrrays?

satya - Friday, June 03, 2011 1:07:17 PM

here is a link on render arrays

here is a link on render arrays

satya - Friday, June 03, 2011 11:22:19 PM

drupal render arrays

drupal render arrays

Search for: drupal render arrays

satya - Friday, June 03, 2011 11:25:07 PM

a step by step exploration of render arrays

a step by step exploration of render arrays

satya - Monday, June 06, 2011 9:46:04 PM

idea of forms

idea of forms

satya - Monday, June 06, 2011 9:56:25 PM

understand drupal forms

understand drupal forms

Search for: understand drupal forms

satya - Monday, June 06, 2011 10:04:13 PM

good forms introduction on drupal 5

good forms introduction on drupal 5

satya - Monday, June 06, 2011 10:14:12 PM

drupal 7 form process flow

drupal 7 form process flow

Search for: drupal 7 form process flow

satya - Monday, June 06, 2011 10:17:20 PM

form api work flow image

form api work flow image

satya - Monday, June 06, 2011 10:38:08 PM

drupal_render

drupal_render

Search for: drupal_render

satya - Monday, June 06, 2011 10:38:57 PM

drupal_render api

drupal_render api

satya - Monday, June 06, 2011 11:24:51 PM

a presentation

a presentation

satya - Tuesday, June 07, 2011 1:29:47 PM

a little bit more on render array: Randy Fay

a little bit more on render array

satya - Tuesday, June 07, 2011 1:43:56 PM

drupal example render array theme function

drupal example render array theme function

Search for: drupal example render array theme function

satya - Tuesday, June 07, 2011 2:26:51 PM

registering a render array theme hook

registering a render array theme hook

Search for: registering a render array theme hook

satya - Tuesday, June 07, 2011 11:15:46 PM

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

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

satya - Tuesday, June 07, 2011 11:17:40 PM

Here is an example of how drupal renders html

Here is an example of how drupal renders html

satya - Tuesday, June 07, 2011 11:18:33 PM

start with a menu so that there is a page call back


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

satya - Tuesday, June 07, 2011 11:24:57 PM

Meaning

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.

satya - Tuesday, June 07, 2011 11:26:17 PM

Returning a data array


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

satya - Tuesday, June 07, 2011 11:28:44 PM

meaning

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.

satya - Tuesday, June 07, 2011 11:34:36 PM

here is the custom theme function


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

satya - Tuesday, June 07, 2011 11:48:21 PM

meaning

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

satya - Tuesday, June 07, 2011 11:49:40 PM

Here is how to register the custom theme function


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

satya - Tuesday, June 07, 2011 11:52:49 PM

Meaning

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.