This is a migrated thread and some comments may be shown as answers.

Conditional rendering syntax

1 Answer 427 Views
Templates
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 17 Jan 2014, 07:37 PM
Hi,

I'm looking to conditionally render HTML-encoded values or literal values depending on a javascript property, such as the following:

<script id="template-cell" type="text/x-kendo-tmpl">
<td><div class="key-content"># if (data.encode === true) { # #= data.key # # } else { # #: data.key # # }#</div></td>
</script>

But all the hash marks reduce readability and are error-prone. What is a better way to handle this?

Thank you.

1 Answer, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 20 Jan 2014, 07:52 AM
Hello Joshua,

If I understand you correctly, a regular indentation of the template would work, too:

<script id="template-cell" type="text/x-kendo-tmpl">
<td>
    <div class="key-content">
        # if (data.encode === true) { #
            #= data.key #
        # } else { #
            #: data.key #
        # } #
    </div>
</td>
</script>

Alternatively, you can extract this logic to a helper function.

Regards,
Petyo
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Templates
Asked by
Josh
Top achievements
Rank 1
Answers by
Petyo
Telerik team
Share this question
or