6

I have some requirement where i have to compare two string values in DWT code like below

 <!-- TemplateBeginIf cond="'title' == 'title'" -->
    .......
    <!-- TemplateEndIf -->
    <!-- TemplateBeginIf cond="'date' == 'date'" -->
     .................
    <!-- TemplateEndIf -->

it looks not working. Now my question is that can i compare string values these way.

P.S.- it may look you guys that why i need this but i am leaving the detail of all requirement here just for the sake of simplicity.

Thanks,

2
  • 2
    String comparisons are definitely possible, this is basic functionality - I assume one of your values is a var, not a string, so maybe what's failing is the syntax for a var in there? Try cond="'date'==varName" without single quotes on the var
    – Nuno Linhares
    Commented Aug 7, 2014 at 15:13
  • +1 Nuno as the code in the above sample is pointless as it should always evaluate to true and thus the conditional region tags can be omitted... Commented Aug 8, 2014 at 11:08

1 Answer 1

8

This is absolutely possible and in your case it is not working because the syntax that you have used is incorrect:

You should have written your code as

<!-- TemplateBeginIf cond="'title'=='title'" -->

Instead of

<!-- TemplateBeginIf cond="'title' == 'title'" -->

Mind the space before and after the equal operator.

Also, consider the suggestion given by Nuno to double check if one of the comparison entity in the if condition is a variable. The variable should not be in surrounded by ' ' whereas the text/string should have been surrounded by them.

2
  • 1
    As the value of the "cond" attribute is evaluated as a JScript expression after expanding package variable references you do NOT need to use @@..@@ here; doing so will in most circumstances create an expression that is always false as @@..@@ gets expanded and afterwards evaluated as a package variable reference... Commented Aug 8, 2014 at 11:11
  • I agree as I have overlooked it. Answer updated :) Commented Aug 8, 2014 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.