I would just write a template tag that outputs the whole JS function.
templates are too limiting in what you can use in {{}} brackets.

konstantin

On Aug 15, 8:38 pm, Landy Chapman <landy.chapm...@gmail.com> wrote:
> You may be right.  I am out of my element (pardon the pun). However,
> assuming your "content" was this:
>
> content = [ { 'roll_no':1, 'cell_no': 1, 'nationality':'nation1'},
> { 'roll_no':2, 'cell_no': 2, 'nationality':'nation2'},
> { 'roll_no':3, 'cell_no': 3, 'nationality':'nation3'},
>
>  the django template renderer will turn this (note quotes around
> nationality and email):
>
> > > $(function() {
> >               i = 0;
> > >             var data = [];
> > >                 {% for x in content %}
> > >                 data[i] =
> > >                 {
> > >                     roll_no: {{x.roll_no}},
> > >                     cell_no: {{x.cell_no}},
> > >                     nationality: '{{x.nationality}}',
> > >                     e_mail: '{{x.e_mail}}'
> > >                 };
> >                     i +=1;
> > >                 {% endfor %}
>
> into this:
>  $(function() {
>                i = 0;
>              var data = [];
>
>                  data[i] =
>                  {
>                      roll_no: 1,
>                      cell_no: 1,
>                      nationality: 'nation 1',
>                      e_mail: 'email1'
>                  };
>                    i +=1;
>                  data[i] =
>                  {
>                      roll_no: 2,
>                      cell_no: 2,
>                      nationality: 'nation2',
>                      e_mail: 'email2'
>                  };
>                    i +=1;
>                  data[i] =
>                  {
>                      roll_no: 3,
>                      cell_no: 3,
>                      nationality: 'nation3',
>                      e_mail: 'email3'
>                  };
>                  i +=1;
>
> My JS guy has left for the day... maybe someone else can help out.
> Also the 'autoescaping' should be on, in case some nationality
> contains a (')  Ex: "G'ermany"
>
> HTH

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

Reply via email to