How can I use {% for ROW in LIST %} within <script type="text/javascript"> tag?

101 views
Skip to first unread message

Pepsodent Cola

unread,
Nov 12, 2013, 7:46:55 PM11/12/13
to django...@googlegroups.com
How can I use {% for ROW in LIST %} within <script type="text/javascript"> tag?  The code I refer to are lines 21 to 25.

http://dpaste.com/1458997/


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<head><!-- HEAD -->
    <title>Navi page</title>
    <meta charset="utf-8">
    <meta name="description" content="Navi-ReactOS wordcloud">
    {% load staticfiles %}
    <link rel="stylesheet" type="text/css" href="{% static 'navi_polls/style.css' %}" />
    <link rel="stylesheet" type="text/css" href="{% static 'navi_polls/jqcloud.css' %}" />
<!-- _______________________________________________________________________ -->
<!-- jQuery -->
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script type="text/javascript" src="{% static 'navi_polls/jqcloud-1.0.4.js' %}"></script>


<!-- jQCloud 2 -->
{% if untranslated_words %}
    <script type="text/javascript">
    /*!
    * Create an array of word objects, each representing a word in the cloud
    */
    var word_array = [
    {% for row in unstranslated_words %} // Hoooooow to use Template tags in javascripts?
        {text: "{{ row.rosword }}", weight: -1},
        {text: "{{ row.rosword }}", weight: -2, link: "http://jquery.com/"},
        {text: "{{ row.rosword }}", weight: -3, html: {title: "I can haz any html attribute"}},
    {% endfor %}
        {text: "Amet-15", weight: -5}
        // ...as many words as you want
    ];

    $(function() {
        /*!
        * When DOM is ready, select the container element and call the
        * jQCloud method, passing the array of words as the first argument.
        */
        $("#wordcloud2").jQCloud(word_array);
    });
    </script>
{% else %}
    <p>No untranslated words are available.</p>
{% endif %}



</head><!-- end HEAD -->




tim

unread,
Nov 13, 2013, 8:18:10 AM11/13/13
to django...@googlegroups.com
Seems like it should work -- what issue or error are you facing?

Daniel Roseman

unread,
Nov 13, 2013, 8:42:29 AM11/13/13
to django...@googlegroups.com
On Wednesday, 13 November 2013 00:46:55 UTC, Pepsodent Cola wrote:
How can I use {% for ROW in LIST %} within <script type="text/javascript"> tag?  The code I refer to are lines 21 to 25.

Why would this be different from using it anywhere else in your template?
--
DR. 

Pepsodent Cola

unread,
Nov 13, 2013, 9:38:36 AM11/13/13
to django...@googlegroups.com
I found out what I did wrong.  It was a simple miss spelling in the most obvious of places.  The jQuery code is fetching data from my database now.  Thanks for the feedbacks it showed me the problem perimeter.

 {% for row in unstranslated_words %}  !=  {% for row in untranslated_words %}

[Solved]


--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/gT4o43Ywp4k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5b8ddec9-1928-4368-b4aa-1ce01ebd0151%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages