Theming forms in your theme
Last updated on
31 August 2016
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
An example about how to theme Drupal Commerce Check Out form:
template.php
/**
* Implements hook_theme().
*/
function yourtheme_theme($existing, $type, $theme, $path) {
$base = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'yourtheme') . '/templates/forms',
);
return array(
'commerce_checkout_form_checkout' => $base + array(
'template' => 'commerce-checkout-form-checkout',
),
);
}
/**
* Preprocessor for commerce_checkout_form_checkout theme.
*/
function yourtheme_preprocess_commerce_checkout_form_checkout(&$variables) {
/* Add or modify your variables */
}
[yourtheme]/templates/forms/commerce-checkout-form-checkout.tpl.php
<?php
// Render or hide parts of $form: var_export($form);
// Example given:
hide($form['title']);
print render($form['first']);
// Render remaining form elements as usual.
print drupal_render_children($form);
?>
Don't forget clearing the theme registry cache.
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion