Expand my Community achievements bar.

Join us on September 25th for a must-attend webinar featuring Adobe Experience Maker winner Anish Raul. Discover how leading enterprises are adopting AI into their workflows securely, responsibly, and at scale.
SOLVED

Substring Helper Function in HTML not working

Avatar

Level 4

Hello, 

 

I have the following code in my HTML I'm trying to use. This code looks for a Campaign Name attribute and applies the corresponding couponID. However, when I try to save this code, I get an "invalid helper substr" error. 

 

{{#each profile._*********.walletInfo.couponDetails as |coupon|}} {%#if contains(coupon.campaignName,"NA_EM_2025_Coupon_Launch" ) %} {% substr(coupon.couponId,38) %} {%else%} No Valid Coupon Available {%/if%}{{/each}}
 
Please advise
 
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@montezh2001 the substr function is missing the syntax. try along these lines,

{{#each profile._*********.walletInfo.couponDetails as |coupon|}}
{%#if contains(coupon.campaignName,"NA_EM_2025_Coupon_Launch") %}
{%= substr(coupon.couponId,0,2) %}
{%else%} No Valid Coupon Available {%/if%}
{{/each}}

 

Thanks, Sathees

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

@montezh2001 the substr function is missing the syntax. try along these lines,

{{#each profile._*********.walletInfo.couponDetails as |coupon|}}
{%#if contains(coupon.campaignName,"NA_EM_2025_Coupon_Launch") %}
{%= substr(coupon.couponId,0,2) %}
{%else%} No Valid Coupon Available {%/if%}
{{/each}}

 

Thanks, Sathees

Avatar

Level 2

Thank you @SatheeskannaK .

 

This worked, despite the documentation stating having the ending index is an option.