1

I have the following Javascript between tags in a template:

YAHOO.util.Event.addListener(window, "load", function() {
YAHOO.example.Taco = function() {
    var myColumnDefs = [
        {% for field in included_fields %}
           {key:"{{ field }}", sortable:true, resizeable:true},
        {% endfor %}
    ];

    var myDataSource = new YAHOO.util.XHRDataSource("http://192.168.1.15:5555/yuidt/list");
    myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
    myDataSource.responseSchema = {
        resultsList: "people",
        fields : [ {{field_list}} ]
    };

    var myDataTable = new YAHOO.widget.DataTable("basic",
            myColumnDefs, myDataSource, {caption:"DataTable Caption"});

    return {
        oDS: myDataSource,
        oDT: myDataTable
    };
}();

});

The value of field_list is the string "first","last","phone"

fields is getting set to nothing some how. So {{field_list}} seems to not be getting rendered.

In the body on the page I have <p>{{field_list}}</p> which displays "first","last","phone" as expected.

This makes me think it is some sort of escaping issue, I tried |addslashes but that was no help.

Any suggestions will be greatly appreciated.

Thanks.

5
  • This could be useful to debug this: docs.djangoproject.com/en/dev/ref/templates/api/…. Furthermore are you sure there's no block tag around the code you show us that may cause this problem? Commented Jun 24, 2010 at 1:59
  • 2
    For what it's worth, use the safe filter to turn off any autoescaping of a string. I really doubt that will fix your problem though. Commented Jun 24, 2010 at 2:03
  • What does the rendered JS look like if you view source? Any chance something is wrong with the Javascript itself? Commented Jun 24, 2010 at 2:33
  • Eric: The safe filter was the solution, thanks. If you post it as the answer I'll happily give you the credit. Commented Jun 24, 2010 at 2:38
  • sdolan: Thanks, to you as well. That was what lead to the above solution, I'm not quite sure how I failed to do that before I posted here. Long day I guess. Commented Jun 24, 2010 at 2:40

1 Answer 1

1

As Eric said it can be resolved using safe filter !

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.