With Django templates, once can either {% extend %} or {% include %} a template. I have a template that already extends another template, and then there are various optional bits of code in templates which get included to the extended template. Thing of these included files as "components" which get added to various templates.
Now one of these inlcuded templates requires an external CSS file. Although one could add the included file to all the templates which include it, I think logically it makes more sense that code snippet injects its own dependencies automatically, or else soft dependencies in far away files tends to get broken. i.e. the included template should declate its needs for the CSS file.
If I write a custom template tag to achieve this, as far as I understand, by the time its gets to this template tag in the included template, it can't go back to the document head and add a line to the rendering of the head to add a <style> tag. So how can one achieve this?
One could add the style tag in the component, but then the style tag is duplicated everytime there's an instance of the component, which is not great.