Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

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,

share|improve this question
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 Aug 7 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... –  Bjørn van Dommelen Aug 8 at 11:08

1 Answer 1

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.

share|improve this answer
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... –  Bjørn van Dommelen Aug 8 at 11:11
    
I agree as I have overlooked it. Answer updated :) –  Pankaj Gaur Aug 8 at 11:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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