Search the FirstSpirit Knowledge Base
Hello,
I am using FS5.1,I would like to compare 2 string using equals method.
If i read the input directly using #content means it is returning as TRUE. using CMS_SET(....) returns FALSE.
Why this behavious is happening?
Example:
$CMS_TRIM(level:4)$$CMS_SET(ltSelectedName)$$CMS_VALUE(content.external_link.getTemplate().getName())$$CMS_END_SET$$CMS_END_TRIM$
<!--ltSelectedName:$CMS_VALUE(ltSelectedName)$-->
<!--compare1:$CMS_VALUE(ltSelectedName.equals("lt_overlaylink_email "))$-->
<!--compare2:$CMS_VALUE("lt_overlaylink_email".equals(ltSelectedName))$-->
<!--compare5:$CMS_VALUE(content.external_link.getTemplate().getName().trim().equals("lt_overlaylink_email"))$-->
Result in the HTML Generation:
<!--ltSelectedName:lt_overlaylink_email-->
<!--compare1:false-->
<!--compare2:false-->
<!--compare5:true-->
Thank you.
Hello Siva,
The reason is that you are simply not comparing Strings 😉
Using $CMS_SET(...)$...$CMS_END_SET$ does not create a String but a template fragment object that will be rendered upon calling $CMS_VALUE(..)$ or .toString() on it - as described in the documentation of $CMS_SET$.
So you have to use
$CMS_VALUE("lt_overlaylink_email".equals(ltSelectedName.toString()))$
Michael
Hello Siva,
The reason is that you are simply not comparing Strings 😉
Using $CMS_SET(...)$...$CMS_END_SET$ does not create a String but a template fragment object that will be rendered upon calling $CMS_VALUE(..)$ or .toString() on it - as described in the documentation of $CMS_SET$.
So you have to use
$CMS_VALUE("lt_overlaylink_email".equals(ltSelectedName.toString()))$
Michael
Just a small addition: In template syntax " == " is mapped to the method "equals". So $CMS_VALUE("lt_overlaylink_email" == ltSelectedName.toString())$ would do the same.
Hello,
Mr. michael anbd Mr. Peter answer is correct.I forgot convert the object as toString().That was the problem.
Thank you both.
<!--toString():$CMS_VALUE("lt_overlaylink_email".equals(ltSelectedName.toString()))$-->
<!--==:$CMS_VALUE("lt_overlaylink_email" == ltSelectedName.toString())$-->
<!--toString():true--> | |
<!--==:true--> |