What is the difference between render elements of #type html_tag (set to div) and container in Drupal 8?
Is the container render element, a simpler version of html_tag? Easier for processing to preprocess container elements?
I note that:
- historically, html_tag was for void elements in the tag in Drupal 7.x.
- if the container element is used a form, it adds the form-wrapper/js-form-wrapper class and an HTML ID if it has #array_parents.
Perhaps my theories are correct (easier to leave be for historical reason / form element reasons)?
PHP:
use Drupal\Core\StringTranslation\TranslatableMarkup;
$variables['myhtml_tag'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#attributes' => [
'class' => 'my-container-class1',
],
'child' => [
'#markup' => new TranslatableMarkup('Some Container text1.'),
],
];
$variables['mycontainer'] = [
'#type' => 'container',
'#attributes' => [
'class' => 'my-container-class2',
],
'child' => [
'#markup' => new TranslatableMarkup('Some Container text2.'),
],
];
HTML:
<div class="my-container-class1">Some Container text1.</div>
<div class="my-container-class2">Some Container text2.</div>
Is the container render element, a simpler version of html_tag?
Iooks like it, also to save having to type the'#tag' => 'div',
part. A dedicated container #type was probably created since it's something used often and makes it easier to use and identify.container
element ?