Skip to content

Instantly share code, notes, and snippets.

@alechko
Last active December 18, 2015 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alechko/5741295 to your computer and use it in GitHub Desktop.
Save alechko/5741295 to your computer and use it in GitHub Desktop.
Drupal table render example
<?php
// Table header
$header = array(
'fruit' => t('Fruit'),
'a' => t('Vitamin A'),
'b1' => t('Vitamin B1'),
'b2' => t('Vitamin B2'),
);
// Table rows
$rows = array(
// Row 1
array(
'fruit' => t('Apple'),
'a' => '98 IU',
'b1' => '0.031 mg',
'b2' => '0.047 mg',
),
// Row 2
array(
'fruit' => t('Banana'),
'a' => '76 IU',
'b1' => '0.037 mg',
'b2' => '0.086 mg',
),
// Row 3
array(
'fruit' => t('Orange'),
'a' => '295 IU',
'b1' => '0.114 mg',
'b2' => '0.052 mg',
),
);
$build['form'] = drupal_get_form('my_form_function');
$build['table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#attributes' => array('id' => 'custom-id','style' => 'width:100%;', 'class' => array('custom-class')),
'#empty' => t('No data to display.'),
);
return $build;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment