在DjangoCMS插件中使用Sekizai addtoblock的正确方法

[英]Correct way to use Sekizai addtoblock in a DjangoCMS plugin


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

我正在开发一个DjangoCMS插件,其中包含一个javascript文件。插件的Javascript依赖于与网站其余部分相同的库。所以,这是我现在所拥有的概念部分:

Basetemplate.html

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's library js.] {% endaddtoblock %}

{% render_block "js" %}
</body>
</html>

Now in the template loaded for my DjangoCMS custom plugin,

现在在为我的DjangoCMS自定义插件加载的模板中,

great_calendar_plugin_template.html

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 plugin javascript files are placed into the final HTML above JQuery and all the other dependencies, rather than underneath where they belong. What am I missing here?

因此,无论我做什么,插件javascript文件都放在JQuery和所有其他依赖项之上的最终HTML中,而不是放在它们所属的下面。我在这里想念的是什么?

Thanks.

谢谢。

1 个解决方案

#1


5  

You can fix this issue by putting the "base" addtoblock calls (jquery, etc) as far at the top of your base template as possible. The important bit is that it's before you call and {% placeholder %} tags, which on most sites means before your opening <body> tag.

您可以通过将“基本”addtoblock调用(jquery等)尽可能地放在基本模板的顶部来解决此问题。重要的是它是在你打电话和{%placeholder%}标签之前,大多数网站上的标签意味着你打开标签之前。

An example 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's library js.] {% endaddtoblock %}

<html>
    <head>
        {% render_block "css" %}
    </head>
    <body>
        {% placeholder "mycontent" %}

        {% render_block "js" %}
    </body>
</html>

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2011/12/24/bb3279aee12bb4c9db0afb617bc387c3.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号