Mark Ellul
Mark Ellul

Reputation: 1906

Django: Template Tags and Javascripts Scripts to match

HI,

I am writing a bunch of template tags for a Django application, that need a certain javascript library.

Each of those template tags could exist multiple times on the same Template.

I was wondering if there is a smart way that I could add the Javscript library in the templatetag templates?

Here is an example TemplateTagA uses customA.js and TemplateTagB uses customB.js.

If I was to say put a extra javascript block tag with {{block.super}} (to not overwrite any other js's added), and TemplateTageA was used 3 times, customA.js would be added 3 times.

So that is not an ideal solution.

I could define in my Base Template a block tag for each script, but that would not be maintainable.

Any other ideas?

I have some more exotic ideas, like pull Javascripts source urls in an array, and then filter before downloading each one via Ajax.

However I am not sure if there are better approaches?

Looking forward to your responses...

Upvotes: 0

Views: 512

Answers (1)

IgorGanapolsky
IgorGanapolsky

Reputation: 26824

I am trying to understand: your template tag values will be javascript blocks? Or are your template values being set in the view?

Upvotes: 2

Related Questions