0

I am using Google Closure template first time.
Can we use Bitwise operator in Google Closure Template.
I want to use some thing like this:

{if $saleStatus.errors & $constant.displayValue}
<div class="displaye">   
<msg desc="user is banned">   
User is Banned.
</msg>   
</div>    
{/if}   

Here i want to use Bitwise operator but i throws error of Syntax Exception.
Or is there any way i should use. May be to include js and do something there ?

Amit T
  • 93
  • 1
  • 2
  • 12

1 Answers1

1

Bitwise AND is not a supported operator in Google Closure templates. You should evaluate this in JavaScript prior to calling the template, and pass it in as a parameter. See the list of supported operators.

For example, something like this...

in JavaScript:

var err = saleStatus.errors & constant.displayValue;
$(elem).html(namespace.myTemplate, { err: err });

in Soy/closure:

....

/**
 * Example ...
 * @param err The error
 */
{template .myTemplate}
    {if err}
        <div class="displaye">   
            <msg desc="user is banned">   
                User is Banned.
            </msg>   
        </div> 
    {/if}
{/template}

For more information about the concepts, please see the documentation.

Code Monkey
  • 1,785
  • 11
  • 13
  • its fine when i have only once but what happens if i have this in for each loop. like {foreach saleStatus in saleStatuses}. in this case i have {saleStatus.errors} may different value each time. – Amit T Oct 26 '13 at 19:00
  • Consider calculating these values prior to rendering the template. You can do this by looping over saleStatuses and adding a new property containing saleStatus.errors & constant.displayValue – Code Monkey Oct 26 '13 at 20:42