Closure template - if condition string contains

3.2k Views Asked by At

I would like to write an if condition and check if a variable contains a certain string and then write some logic.

if i have a variable say @param activity

How can I check that variable activity contains the string "abc"?

2

There are 2 best solutions below

0
On

From the documentation (https://developers.google.com/closure/templates/docs/functions_and_directives), there is the strContains method:

strContains(str, subStr) - Checks whether a string contains a particular substring.

{if strContains($activity, 'abc')}
    // ...
{/if}
1
On

If you browse Closure Templates Documentation, you should be able to find what you're looking for, especially the if section. Regardless, here's an example:

{namespace com.company.my}

/**
 * My Template 
 * @param activity
 */
{template .main}
    {if $activity == 'abc'}
        //do stuff
    {/if}
{/template}