views:

134

answers:

1

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...

+1  A: 

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

PythonUser
Thanks for you question. Basically I have created template tags which are widgets, html and javascript. The developer who worked on this project inserted script tags inside the template tag html. however this mean't alot of repetition when the same template tag was used multiple times on a page.So i created a javascript script that contained a function for the template tag. I thought it would be cool if I could insert the include script tag IF it had not been included on this page already. Thus reducing the need to add the include script tag in the page template.
Mark Ellul

related questions