ListView template calling an async function using await

1 Answer 66 Views
ListView Templates
Ed
Top achievements
Rank 1
Ed asked on 30 Jan 2025, 11:56 PM
Hi. I have a listview with an html template. I need to call an async function to get an image url from our service based on the value of one of the returned fields. How can I use await in the template? Or is it even possible? This is a simplified part of my template. I tried a few different ways to get it to work, but just get an invalid template error. Any help is appreciated.

<script type="text/x-kendo-template" id="lvProducersTemplate">
     <div>
          <div>
             #if(RFLogoId) {
                var logoUrl = await utils.getRFLink(RFLogoId);
             }#
             <img alt="profile img" src="#:logoUrl#">                            

          </div>
</div>
</script>

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 04 Feb 2025, 08:32 AM

Hello, Ed,

The syntax for the template seems incorrect, as you are missing some # symbols. Here's how to fix the invalid template error:

<div>
             # if(RFLogoId) { #
                var logoUrl = await utils.getRFLink(RFLogoId);
             # } #
             <img alt="profile img" src="#:logoUrl#">                            
      </div>

On my side, I am now getting a logonUrl is not defined error due to the missing async function. You can also check this forum thread which seems to discuss a similar topic about calling an async function as template.

Let me know if that would work for you.

Regards,
Martin
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ListView Templates
Asked by
Ed
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or