# Condition in html action section not working

**URL:** <https://discuss.elastic.co/t/condition-in-html-action-section-not-working/133469>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [May 28, 2018, 6:35am UTC](https://discuss.elastic.co/t/condition-in-html-action-section-not-working/133469 "2018-05-28T06:35:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leela\_kumili](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leela_kumili/32/85841_2.png) [@leela\_kumili](https://discuss.elastic.co/u/leela_kumili)\
**Post date:** [May 28, 2018, 6:35am UTC](https://discuss.elastic.co/t/condition-in-html-action-section-not-working/133469/1 "2018-05-28T06:35:53Z")

</div>

Hi all,

I want to send email from x-pack watcher and content in email varies depending on values. I tried writing if else condition, its not evaluating the condition treating as a text.

Any idea how to do it?

"actions": {  
"send\_email": {  
"email": {  
"profile": "standard",  
"to": [  
"xxxx@gmail.com"  
],  
"subject": " Alert",  
"body": {  
"html": "

Hi Team,  
  
 Here is comparison report of 'Add To Bag' trends form each source for past 2 hours:

 
 
   
 
 {{#ctx.payload.\_value}} {{#Page}} {{#source}}**if({{percentage \< 0.0}})** {{/source}} {{/Page  
}} {{/ctx.payload.\_value}} 

 | Application | Page | Sourcr | Earlier Count | Latest Count | Trending Up/Down |
| --- | --- | --- | --- | --- | --- |
 |
| |
| {{App}} | {{page}} | {{src}} | {{earlier}} | {{latest}} | {{percentage}} |

 

For details refer to chart : \<a href=index.html"\>AddToBagTrends
"  
}  
}  
}  
}

I want to change color of percentage cell to red is less than 0 , to green if greater than zero.

But instead of evaluating the condition if printing as text replace {{percentage}} variable as text like this : -46.75156796093264 \< 0.0

Any idea how to tell watcher to evaluate the condition and not to treat as text.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 25, 2018, 6:35am UTC](https://discuss.elastic.co/t/condition-in-html-action-section-not-working/133469/2 "2018-06-25T06:35:53Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [July 3, 2018, 9:06am UTC](https://discuss.elastic.co/t/condition-in-html-action-section-not-working/133469/3 "2018-07-03T09:06:06Z")

</div>

hey,

mustache follows the principle of being a so-called logic less template language, trying not to have these kind of constructs. There are similar constructs though, see this page [https://www.elastic.co/guide/en/elasticsearch/reference/6.3/search-template.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.3/search-template.html)

However, you might be better off using a `transform` in your action, that adds a new field called `color` and doing the calculation in the script to decide if color should be `red` or `green`.

Fore more information about transforms, see [https://www.elastic.co/guide/en/elastic-stack-overview/6.3/transform-script.html](https://www.elastic.co/guide/en/elastic-stack-overview/6.3/transform-script.html)

Hope this helps.
