Filing this in "forms system", because there is no "render system" or "render elements".

The 90% use-case for #prefix and #suffix is surrounding the element in a < div >. With #type 'markup' this doesn't work. You can, of course, wrap the actual #markup in the < div >, but it seems more flexible and also conceptually sensible to separate the actual #markup from something that is just wrapping it.

I'm not aware of any downsides of this, but I'm not that intimate with the render system, so that isn't saying a whole lot.

Not rolling a patch, because I'd like to hear some opinions on this first, but it shouldn't be too hard.

@see drupal_pre_render_markup()

Comments

fran seva’s picture

Assigned: Unassigned » fran seva
Issue summary: View changes
fran seva’s picture

Assigned: fran seva » Unassigned
petar.gnjidic’s picture

Assigned: Unassigned » petar.gnjidic

I'll take this.

petar.gnjidic’s picture

Assigned: petar.gnjidic » Unassigned
tim.plunkett’s picture

Component: forms system » render system
'#type' => 'container',
'#children' => 'some string',
joelpittet’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Active » Closed (cannot reproduce)

You can do this:

bartik.theme

function bartik_preprocess_page(&$variables) {
  $variables['wrap_me_up'] = [
    '#prefix' => '<div class="am-i-a-template">',
    '#markup' => '<span>WRAPPED UP AND SHOULD BE A TEMPLATE</span>',
    '#suffix' => '</div>',
  ];
}

bartik/templates/page.html.twig

  {{ wrap_me_up }}

Produces:

<div class="am-i-a-template"><span>WRAPPED UP AND SHOULD BE A TEMPLATE</span></div>