opentext-idol/find

custom handlebars templates - how to condition style attributes

Closed this issue · 9 comments

Dear Sirs,

I developed a custom handlebars template for some custom IDOL DREfields. The trigger is: if those fields are present in a returned Idol result, the template is applied to such a result, in the List Panel

Now I need to implement a further condition, of CSS-style fashion: if the {{summary}} field contains the string "NON-AUTORIZZATO" the color of the Summary must be 'darkred', if not it must be '#a2a2a2'

So, I added in my template a

with the following ternary-conditioning in the style attribute value:

<div class="document-database m-t-xs m-l-xs" 
   style="{{ (summary.indexOf('NON-AUTORIZZATO') != -1) ? 'color:darkred;' : 'color:#a2a2a2;' }}">
      {{summary}}
</div>

but it does not work. It gives an angular syntax error, in the browser console: unespcted symbol (at the beginning of the style value)
NOTICE: all the remnant template code, both html, angular and handlears works well!
I attach it here

sasc.handlebars.txt

It's a handlebars template, not arbitrary javascript code. You should use the #equal helper instead, something like

{{#equal summary 'NON-AUTORIZZATO'}} something {{else}} something else {{/equal}}

The Find Admin guide on https://www.microfocus.com/documentation/idol/IDOL_12_0/Find_12.0_Documentation.zip has a list of all the available helpers.

I am trying the 'regeIf' helper, according to Find 12 pdf Guide. (I need to check contains, not equal)
But I always get this error:
"Missing helper: "regexIf" "

my code being as follows:

{{#regexIf '.*NON-AUTORIZZATO.*' summary i }}
	<div class="document-database m-t-xs m-l-xs" style="color: darkred !important;">
		{{summary}}
	</div>
{{else}}
	<div class="document-database m-t-xs m-l-xs">
		{{summary}}
	</div>
{{/regexIf}}

where the 'i' param is a flag that means case-insensitive. What is wrong ?
NOTICE: documentation lacks to evidence if the regexIf accepts a {{else}} branch

Also I tried another built-in helper hasFieldValue:

{{#hasFieldValue summary "NON-AUTORIZZATO" }}
	<div class="document-database m-t-xs m-l-xs" style="color: darkred !important;">
		{{summary}}
	</div>
{{else}}
	<div class="document-database m-t-xs m-l-xs">
		{{summary}}
	</div>
{{/hasFieldValue}}

It gives me no errors, but it does not work as a string.contains. The block is always false

hasFieldValue 'contains' is array contains, not string contains. Basically a field can take multiple values, not just one; the test will pass if any one of those values is an exact match for the string to test.

This is the syntax for regexIf

{{#regexIf '\d+' title }}
  <div>title contains a number</div>
{{else}}
  <div>title does not contain a number</div>
{{/regexIf}}

and I've tested it and it works for me.

image

Are you using the standard 12.0 release, or your own customized version of it? The regexIf helper is defined in
https://github.com/microfocus-idol/find/blob/cdb8fb57039091f95fe530005fa64198ceb1f83f/webapp/core/src/main/public/static/js/find/app/page/search/document-renderer.js#L137
so you should have it if you're using 12.0.

Also in your example, the 'i' flag should be in quotes, in fact it's a option so it should be like this:

{{#regexIf 'A' title flags='i' }}
  <div>title contains an A case-insensitive</div>
{{else}}
  <div>title does not contain an A case-insensitive</div>
{{/regexIf}}

Tung,
thank you v.m.
I already used #regexIf without success, because: the problem was the last U mentioned: flags='i' !!!
Now the conditional block works well

We can close this issue