On Tuesday, April 16, 2013 11:41:56 AM UTC+8, Nora Olsen wrote:
>
> Hi,
>
> I have seen some discussion in this group on how to handle duplicate 
> form.media in template includes.
>
> I have the following the following base.html with scripts at the end of 
> the body. I am following h5bp convention:
>
>         <script src="//
> ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
>         <script>window.jQuery || document.write('<script src="{{ 
> STATIC_URL }}js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
>
>         <script src="{{ STATIC_URL }}js/vendor/bootstrap.min.js"></script>
>         <script src="{{STATIC_URL }}js/main.js"></script>
>
>         {% block script %}{% endblock %}
>        </body>
>
> In my actual template, I include multiple templates and they 
> are independent and reusable:
>
> {% extends "base.html" %}
> {% block script %}
> <script src="{{ STATIC_URL }}js/vendor/jquery.chained.remote.js"></script>
> <script src="//
> ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
> <script>...</script>
> {% endblock script %}
>
> {% block content %}
> {% include "sub_template1.html" %}
> {% include "sub_template2.html" %}
> {% endblock %}
>
>
> In sub_template, I do have js scripts too and within the script block. But 
> according to the docs, include “render this subtemplate and include the 
> HTML”. 
>
> And these sub templates have common js scripts because I'm trying to keep 
> them independent so that I can reuse the forms in other places in my app.
>
> 1. I can't seem to modularize my template/forms using include statement 
> and have them loaded at the end of the page using the block tag. 
>
> 2. How to avoid the duplication?
>
> What should the right approach to solve the problems?
>
>
>
After reading the docs again, it seems that there is no shared state. I 
should be able to do the following:

{% block script %}
<script src="{{ STATIC_URL }}js/vendor/jquery.chained.remote.js"></script>
<script src="//
ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script>...</script>

*          <script src="{{ STATIC_URL }}js/sub_template1.js"></script>*
*          <script src="{{ STATIC_URL }}js/sub_template2.js"></script>
*
*          <script src="{{ STATIC_URL 
}}js/common_third_party_script_between_sub_template1_and_2.js"></script>
*

{% endblock script %}

{% block content %}
{% include "sub_template1.html" %}
{% include "sub_template2.html" %}
{% endblock %}


The JS scripts will be removed from the sub templates and moved to their 
individual js files. Then I will be manually removing the duplication by 
only including 1 copy of the common scripts. In that way, I won't be able 
to use form.media?
 
Not perfect but I guess it works?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to