Search code examples
jquerygoogle-chromejquery-templates

JQuery templates {{if}} statement doesn't work in Chrome


It will, however, work in IE, or Firefox. Any suggestions?

Edit: IRT Pointy's observation: There were no errors of any kind. This page simply did not render anything more than the html that was in the section.

<html>
    <head>
        <script src="scripts/jquery-1.4.4.min.js"></script>
        <script src="scripts/jquery.tmpl.js"></script>
        <script id="template" type="text/x-jQuery-tmpl">
            <tr>                
                <td>${field1}</td>
                <td>
                    {{if field2 ==="hello" }}
                      <b>if statement</b>
                    {{else }}
                      <i>else statement</i>
                    {{/if }}
                </td>
            </tr>
        </script>
        <script type="text/javascript">
        var data = [
                        { field1: "yayayaya1", field2: "oyoyoyo1"},
                        { field1: "yayayaya2", field2: "hello"},
                        { field1: "yayayaya3", field2: "oyoyoyo3"}
                   ];               
        $(function() 
        {
            $("#template").tmpl(data).appendTo("#table1");
        });
        </script>
    </head>
    <body>
        <table id="table1">
          <thead>
            <tr>
                <th>field1</th>
                <th>field2</th>
            </tr>            
        </thead> 
        </table>
    </body>
</html>

Solution

  • It didn't work in Firefox (3.6) either when I tried it. But changing {{else }} to {{else}} fixed the problem in both browsers.