The correct way to use Sekizai addtoblock in the DjangoCMS plugin

I am working on a DjangoCMS plugin that includes a javascript file for myself. The Javascript plugin relies on the same libraries as the rest of the site. So, here is the conceptual part of what I have right now:

Basetemplate.html

{% load cms_tags sekizai_tags and_a_bunch_of_other_stuff %} <html> ... <head> {% render_block "css" %} </head> <body> ... {% addtoblock "js" %}[jquery]{% endaddtoblock %} {% addtoblock "js" %}[google api, data, more cool stuff like jqplot.]{%endaddtoblock%} {% addtoblock "js" %}[my site library js.] {% endaddtoblock %} {% render_block "js" %} </body> </html> 

Now in the template downloaded for my custom DjangoCMS plugin,

great_calendar_plugin_template.html

 {% load sekizai_tags and_a_couple_other_things %} {% addtoblock "js" %}[plugin javascript file dependency]{%endaddtoblock %} {% addtoblock "js" %}[plugin javascript file]{% endaddtoblock %} .... 

So, no matter what I do, the javascript files of the plugin are placed in the final HTML above jQuery and all other dependencies, and not under them where they belong. What am I missing here?

Thanks.

+8
django django-cms django-sekizai
source share
1 answer

You can fix this problem by placing the "base" addtoblock calls (jquery, etc.) as far as possible at the beginning of the base template. The important bit is that it is up to you call and {% placeholder %} tags, which on most sites mean before opening the <body> .

An example of a dummy template:

 {% load cms_tags sekizai_tags and_a_bunch_of_other_stuff %} {% addtoblock "js" %}[jquery]{% endaddtoblock %} {% addtoblock "js" %}[google api, data, more cool stuff like jqplot.]{%endaddtoblock%} {% addtoblock "js" %}[my site library js.] {% endaddtoblock %} <html> <head> {% render_block "css" %} </head> <body> {% placeholder "mycontent" %} {% render_block "js" %} </body> </html> 
+5
source share

All Articles