nortmas
9/27/2017 - 2:50 PM

Force render

$build['list'] = [
  '#theme' => 'item_list',
  '#items' => [
    ['#markup' => $item],
    ['#markup' => $item2]
  ],
  '#attached' = ['library' => ['custom/styles']],
];


// Convert $build to HTML and attach any asset libraries.
$html = \Drupal::service('renderer')->renderRoot($item_list);

// Convert to HTML, ignore asset libraries. Useful when you need just the HTML
// and don't care about attached assets.
$plain = \Drupal::service('renderer')->renderPlain($item_list);