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:
<ul>
{% block plugins %}
{% endblock %}
</ul>
This way, any plugin modules can add <li><a href='flot-examples/[plugin_name]'>plugin example</a>
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?
Hooks
. You define a hook_alter in a module that provide the block and others modules implement this hook_alter, that is it.