Skip to content

Instantly share code, notes, and snippets.

@opi
Created August 6, 2013 12:43
Show Gist options
  • Save opi/6164121 to your computer and use it in GitHub Desktop.
Save opi/6164121 to your computer and use it in GitHub Desktop.
Drupal: tabbed block with jQuery UI
<?php
function my_module_my_tabbed_block() {
// Block title
$block['subject'] = t("My tabbed block");
// Tabs.
$block['nav'] = array(
'#theme' => 'item_list',
'#items' => array(
l(t('Item 1'), '', array('fragment' => 'item-1', 'external' => TRUE)),
l(t('Item 2'), '', array('fragment' => 'item-2', 'external' => TRUE)),
l(t('Item 3'), '', array('fragment' => 'item-3', 'external' => TRUE)),
),
'#attributes' => array('class' => array('tabs'))
);
// Content.
$block['item1'] = array(
'#prefix' => '<div id="item-1">',
'#suffix' => '</div>',
'content' => array(
'#type' => 'markup',
'#markup' => "my content 1",
),
);
$block['item2'] = array(
'#prefix' => '<div id="item-2">',
'#suffix' => '</div>',
'content' => array(
'#type' => 'markup',
'#markup' => "my content 2",
),
);
$block['item3'] = array(
'#prefix' => '<div id="item-3">',
'#suffix' => '</div>',
'content' => array(
'#type' => 'markup',
'#markup' => "my content 3",
),
);
// jQuery UI tabs library
$block['#attached'] = array(
'library' => array(
array('system', 'ui.tabs')
),
'js' => array('
jQuery(document).ready(function(){
jQuery("#block-my-module-my-tabbed-block > .content").tabs();
});' => array('type' => 'inline')
)
);
return $block;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment