If statement in template not working

2 posts, 0 answers
  1. Nisarg
    Nisarg avatar
    12 posts
    Member since:
    Dec 2014

    Posted 05 Jan 2015 Link to this post

    Hi there,

    I have a template as follows:

    <script id="rowTemplate" type="text/x-kendo-tmpl">
            <tr data-uid="#: data.id #">
                <td>
                    <img src="lib\\images\\catalog\\item#: data.itemid #.jpg" alt="#: data.item #" />
                </td>
                <td>
                    <span>#: data.item #</span>
                </td>
                <td>
                    $#: data.price #
                </td>
                <td>
                    #: data.qty #
                </td>
                <td>
                    #: data.date #
                </td>
                <td>
                    #if( data.processed === "true"){#
                    <img src="lib\\images\\orders\\check.png" alt="Processed" />
                    #}#
                    #else {#
                    <img src="lib\\images\\orders\\inprogress.gif" alt="In Progress" />
                    #}#
                </td>
                <td>
                    #if( data.delivered === "true"){#
                    <img src="lib\\images\\orders\\check.png" alt="Delivered" />
                    #}#
                    #else {#
                    <img src="lib\\images\\orders\\inprogress.gif" alt="In Progress" />
                    #}#
                </td>
            </tr>
        </script>


    And I have the respective fields in my data. But I get an invalid template error on this template.
    If I replace the last two "<td>"s with simpler form like
    <td>
    data.processed
    </td>
    <td>
    data.delivered
    </td>

    It works perfectly. So please let me know where I am wrong.

    Thank you in advance, Nisarg
  2. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 06 Jan 2015 Link to this post

    Hello Nisarg,

    you should concatenate the } else { part into a single # # block. An excerpt from our documentation:

       <script type="text/x-kendo-template" id="myTemplate">

            #if(isAdmin){#
                <li>#: name # is Admin</li>
            #}else{#
                <li>#: name # is User</li>
            #}#
        </script>

     

    Regards,
    Petyo
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
Back to Top