Correct way to do if statement in a client template?

1 Answer 22005 Views
Templates
Scott
Top achievements
Rank 1
Scott asked on 04 Feb 2013, 09:00 PM
I'm trying to put a conditional in a client template and can't figure out where in the docs this is addressed. Could you point me to the correct area? Here's the code that's not working. The conditional is "CanBeOverturned":

columns.Template(@<text></text>).ClientTemplate("<div>Reviewed Date : \\#=SubmissionDateString\\# | \\#=CorrectiveActionName\\# \\# if (CanBeOverturned == true) { <a href='javascript:var t=0;' onclick='javascript:return openOverturn(\"\\#=FeedbackFormId\\#\")' style='float:right;' class='openFeedbackForm')>+ Overturn</a> }</div>");

Thanks in advance for any help you can provide!

1 Answer, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 05 Feb 2013, 08:40 AM
Hello Scott,

There is an if example at the very bottom of this documentation article. Please let us know if you still experience troubles with your implementation.

Regards,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Joe
Top achievements
Rank 1
commented on 13 Aug 2013, 02:46 PM

Hi Petyo,
I'm struggling with the syntax of this conditional statement. I've studied the online documentation but no success.
.ClientFooterTemplate("<div>Avg: # if(data.TotalSalesAmt.sum == 0) {#= kendo.toString(0,'P2'); #}# else {#= kendo.toString(data.TotalMarginAmt.sum / data.TotalSalesAmt.sum,'P2'); #}# </div>")
Petyo
Telerik team
commented on 15 Aug 2013, 11:26 AM

Hello,

As far as I see, there are some mismatched # symbols in your template. Try breaking the template to multiline string in order to debug it. 

Regards,
Petyo
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Joe
Top achievements
Rank 1
commented on 19 Aug 2013, 04:04 PM

Breaking the statement up into separate lines was a good suggestion. This worked:
.ClientFooterTemplate("# if(data.TotalSalesAmt.sum == 0) " +
                                           "{# <div>Avg: #= kendo.toString(0,'P2') # </div>#} " +
                                           "else {# <div>Avg: #= kendo.toString(data.TotalMarginAmt.sum / data.TotalSalesAmt.sum,'P2') # </div> #}#"
)
Doug
Top achievements
Rank 2
commented on 02 May 2020, 02:04 PM

Hi, Is there a #: (mightbeNull)??(nullAternative) #
I get a fail if i leave of the "#}# else {#" 
This is because I wanted to add in a comma if a additional field had a value eg Address3 is often empty where as Address1 always has the street details. Trying to apply what works in handlebars{} to this where there are hole in the docs :/

 

Martin
Telerik team
commented on 05 May 2020, 04:52 PM

Hello Doug,

The suggested syntax is not supported in Kendo Templates. Could you please provide an example demonstrating the issues you are experiencing with the regular if-else statements? Maybe I will be able to suggest something to make it work.

Looking forward to your reply.

Regards,
Martin
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Doug
Top achievements
Rank 2
commented on 05 Jul 2020, 12:00 PM

Would be nice to see the URL to the complete guide to 'KendoUI Template Syntax' so when you google those 3 key words you end up at https://docs.telerik.com/kendo-ui/framework/templates/overview

 

Martin
Telerik team
commented on 07 Jul 2020, 02:40 PM

Hello Doug,

Could you please provide some additional information about your last post? Is there a broken link to the Template article? Or is the link not on the top of the Google results when you type the three keywords you mentioned? 

Regards,
Martin
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Petar
Telerik team
commented on 16 Aug 2021, 12:23 PM

Hi everyone. 

It has been reported that the link from the post of Petyo is not working. If someone needs the correct link it can be found here.

Tags
Templates
Asked by
Scott
Top achievements
Rank 1
Answers by
Petyo
Telerik team
Share this question
or