| 7 theme.inc | theme_html_tag($variables) |
| 8 theme.inc | theme_html_tag($variables) |
Returns HTML for a generic HTML tag with attributes.
Parameters
$variables: An associative array containing:
- element: An associative array describing the tag:
- #tag: The tag name to output. Typical tags added to the HTML HEAD:
- meta: To provide meta information, such as a page refresh.
- link: To refer to stylesheets and other contextual information.
- script: To load JavaScript.
- #attributes: (optional) An array of HTML attributes to apply to the tag.
- #value: (optional) A string containing tag content, such as inline CSS.
- #value_prefix: (optional) A string to prepend to #value, e.g. a CDATA wrapper prefix.
- #value_suffix: (optional) A string to append to #value, e.g. a CDATA wrapper suffix.
- #tag: The tag name to output. Typical tags added to the HTML HEAD:
Related topics
1 call to theme_html_tag()
- ThemeHtmlTag::testThemeHtmlTag in modules/
simpletest/ tests/ theme.test - Test function theme_html_tag()
1 theme call to theme_html_tag()
- drupal_get_js in includes/
common.inc - Returns a themed presentation of all JavaScript code for the current page.
File
- includes/
theme.inc, line 2172 - The theme system, which controls the output of Drupal.
Code
function theme_html_tag($variables) {
$element = $variables['element'];
$attributes = isset($element['#attributes']) ? drupal_attributes($element['#attributes']) : '';
if (!isset($element['#value'])) {
return '<' . $element['#tag'] . $attributes . " />\n";
}
else {
$output = '<' . $element['#tag'] . $attributes . '>';
if (isset($element['#value_prefix'])) {
$output .= $element['#value_prefix'];
}
$output .= $element['#value'];
if (isset($element['#value_suffix'])) {
$output .= $element['#value_suffix'];
}
$output .= '</' . $element['#tag'] . ">\n";
return $output;
}
}
Comments
Sample Use
Permalink<?phptheme('html_tag', array(
'element' => array(
'#tag' => 'h2',
'#attributes' => array(
'class' => 'activities-sidbar',
),
'#value' => 'Activity History',
),
));
?>
No children
PermalinkIt seems that this won't support rendering children without extra help.
I'd expected :
<?php$test = array(
'#type' => 'html_tag',
'#tag' => 'div',
'#attributes' => array('class' => 'outer'),
'0' => array(
'#type' => 'html_tag',
'#tag' => 'span',
'#attributes' => array('class' => 'inner'),
'#value' => 'Content',
),
);
?>
to produce
<div class="outer"><span class="inner">
Content
</span>
</div>
but it fails.
Looks like you will have to call render() or drupal_render_children() on the child items yourself, and set the #value of your html_tag before allowing the normal render process to use it.
Could be that this desired behavior could happen with an alter of hook_preprocess_html_tag() as well... Though I think it's not asking too much for this low-level utility to behave as if it knows how to render HTML child elements.