We created a template tag which adds a button that opens a dialog (to display additional information).
The dialog needs an extra js file and one css file.
At the moment, both, the js and the css file is added as global requirement in our Django application. But, because the dialog is only needed on some special Django views, we would like to remove the js/css file from global requirements.
But we are not able to add the files automatically if the view includes the template tag. There is nothing like the Media classes for Django forms. (see: https://docs.djangoproject.com/en/1.8/topics/forms/media/)
With takes_context=True it is possible to read the context in template tags, but we are not able to add files, because the context is only a pass by value of the original Django context.
Any ideas how to add js/css files only to the html header if the template tag is existent in a template?