Injecting additional content from multiple sources into a block using twig I have a module which presents a table of contents from a twig template of examples on to how to use the module. This listing is located at /flot-examples. I would like additional modules to be able to add links to this list. The main module, flot_examples has a block, plugins defined like this:

&lt;ul&gt;
{% block plugins %}
{% endblock %}
&lt;/ul&gt;


This way, any plugin modules can add &lt;li&gt;&lt;a href='flot-examples/[plugin_name]'&gt;plugin example&lt;/a&gt; to the list

If I have only one plugin, I think I could override the route to /flot-examples by the plugin, call {{ parent() }} and inject content into {% block plugins %} However, if I have multiple plugins, they all can't do that.

I also see that there is a way for the parent to identify child scripts as 'appendable': 

{% use [child_module].html.twig with appendable as appendableContent %}


This would work, but the parent module would have to be given a list of the child modules. If this is the best way to accomplish this, I imagine I would have to:

1)add an array to the parent module, flot_examples, (where?) so that...

2)the child modules would append their names to (where?) so that ...

3)when this array is passed to the twig template (flot_examples.module and somewhere else?), it can loop over the array (in the twig temple) to generate the {% use .... %} statement.

I guess I can see another strategy would be to move this directory listing out of a twig template, and just use render arrays. Then would the child module use preRender functions to append additional list items to the render array, somehow?

Are any of these on the right track? Which would be "the best" or "the easiest" way?
I went with a hook instead. There must not be a way to do this in twig.

This section resides in a controller in the parent module:

$plugin_items = [];
// Call modules that implement the hook, and let them add items.
\Drupal::moduleHandler()-&gt;alter('flot_examples_toc', $plugin_items);
if (count($plugin_items &gt; 0)) {
  $output['plugins'] = [
    '#title' =&gt; 'Plugins',
    '#theme' =&gt; 'item_list',
    '#items' =&gt; $plugin_items,
  ];
}


And this resides in the child [module].module file.

&lt;?php
use Drupal\Core\Url;
function flot_spider_examples_flot_examples_toc_alter(&amp;$item_list) {
 $options = [
      ':one' =&gt; Url::fromRoute('flot_spider_examples.example')-&gt;toString(),
    ];
 $item_list[] = t('&lt;a href=":one"&gt;Spider Chart&lt;/a&gt; (with spider plugin)', $options);


}

The parent creates an array and passes it to the children by reference. They can alter the array by adding elements to it. The parent then adds it to the render array.