Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Advanced theming


Published on

Published in: Technology, Travel
  • Be the first to comment

Advanced theming

  1. 1. Drupal Advanced Theming DrupalCamp Estonia Kaido Toomingas 14.June 2012
  2. 2. Problem● You need more than Drupal theme can offer you out of box● You dont need some stuff wich Drupal offers You out of box
  3. 3. Solutions● Lets just put this into templates ;) What does Your designer would say?● What should I do then?● Template.php● Custom module
  4. 4. How can I implement this?● Hooks? Examples...?● TEMPLATE_preprocess(&$variables, $hook)● HOOK_form_alter(&$form, &$form_state, $form_id)● theme($hook, $variables = array())● THEMEHOOK_settings() in theme-settings.php● THEMENAME_form_system_theme_settings_alter(&$form, $form_state)● hook_theme_registry_alter()
  5. 5. HooksHooks in drupal are functionswich will help you to change orextend default functionality.
  6. 6. Preprocess● TEMPLATE_preprocess(&$variables, $hook)● TEMPLATE_preprocess_HOOK(&$variables)● Manipulate or create variables. Example page variables. You can add these into template.php. Example: function template_preprocess_foo(&$variables) { $variables[foo_list] = array( list item 1, list item 2, list item 3, ); }
  7. 7. Modify forms● HOOK_form_alter(&$form, &$form_state, $form_id)● hook_form_FORM_ID_alter ● Change existing form elements by changing or adding some arrays. ● Create new form elements – There is better way.Example:function example_form_alter(&$form, &$form_state, $form_id) { dsm($form_id); // print form ID to messages You need develmodule switched for using dsm() function dsm($form); // pretty print array using Krumo to messages}
  8. 8. Theme some data● theme($hook, $variables = array())● Usecase: You want to create a table, image or some other element from you data. You should use theme function for that.● Usage: Can be used in template.php or custom modules. Example: theme(table, array( header => $header, rows => $options, attributes => array(class => array(mytable)) ));
  9. 9. hook_theme_registry_alter()● This is the most powerful themer helper wich should be used only when cant find any way to change your theme.● You can use this when there is module wich doesnt have proper theme fuctions wich could be overwritten.