Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Beakerboy on
I have the following in a simple Drupal 8 controller. I would like to add an item to an item list that has two different links and some text, but cannot figure out how to do it. In my code below, the first bullet point is just a link. The second is just some text. The third is will print each link as escaped HTML and concatinate them with the " and ". How do I print a combination of links and text in an item list?
$basic_items[] = Link::createFromRoute('Basic example','flot_examples.basic_usage');
$basic_items[] = "Different graph types and simple categories/textual data";
$basic_items[] = Link::createFromRoute('Different graph types', 'flot_examples.series_types')->toString() .
" and " .
Link::createFromRoute('simple categories/textual data', 'flot_examples.categories')->toString();
$output['basic'] = [
'#title' => 'Basic Usage',
'#theme' => 'item_list',
'#items' => $basic_items,
];
return $output
Comments
Achieve it by using a
Achieve it by using a renderable array for each item:
Maybe late but useful for other. I have spent time on to found the solution...
In my case, I'd like to add an item list in a ListViewBuilder row, and I used:
I used the renderer service to render the renderable array because the row take a string.
http://www.sabugo.ch
http://www.titouille.ch
I think the best solution is
I think the best solution is to use something like: