7.x form.inc theme_container($variables)

Returns HTML to wrap child elements in a container.

Used for grouped form items. Can also be used as a theme wrapper for any renderable element, to surround it with a <div> and add attributes such as classes or an HTML ID.

See the Form API reference for more information on the #theme_wrappers render array property.

Parameters

$variables: An associative array containing:

  • element: An associative array containing the properties of the element. Properties used: #id, #attributes, #children.

Related topics

File

includes/form.inc, line 3403
Functions for form and batch generation and processing.

Code

function theme_container($variables) {
  $element = $variables['element'];
  // Ensure #attributes is set.
  $element += array('#attributes' => array());

  // Special handling for form elements.
  if (isset($element['#array_parents'])) {
    // Assign an html ID.
    if (!isset($element['#attributes']['id'])) {
      $element['#attributes']['id'] = $element['#id'];
    }
    // Add the 'form-wrapper' class.
    $element['#attributes']['class'][] = 'form-wrapper';
  }

  return '<div' . drupal_attributes($element['#attributes']) . '>' . $element['#children'] . '</div>';
}

Comments

amagdy’s picture

I found no example here, so i though about sharing mine

theme('container', array(
    'element' => array(
      '#children' => l(t('Login'), 'user', array('query' => array('destination' => current_path()))),
      '#id' => 'login-link',
      '#attributes' => array(
        'class' => array(
          'container'
        )
      )
    )
  ));
georgir’s picture

No, this is the wrong way to use it. it is intended to be used as part of render arrays and formapi arrays, via '#type'='container' or '#theme_wrapper'='theme_container'.

$form['some_wrapper']=array(
  '#type' => 'container',
  'some_child' => array(...),
  'other_child' => array(...),
)
roynilanjan’s picture

If I want to render a custom container with some special custom css class and attributes

ttkaminski’s picture

$build['some_wrapper'] = array(
  '#theme_wrappers' => array('container'),
  '#attributes' => array('class' => array('some_class')),
  'some_child' => array(...),
  'other_child' => array(...),
);