Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > If statment in transformation View modes: 
User avatar
Member
Member
eagleag - 3/2/2010 8:33:38 AM
   
If statment in transformation
Hi,
I'm trying to get this working in a transformation.

<% if (Eval("Featured") == "True" %>
<b>Hello </b>
<% else %>
<b> bye</b>

"Featured" is a bool field.

Is there a way to do this without creating custom functions outsie the transformation?

thanks

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 3/2/2010 9:33:14 AM
   
RE:If statment in transformation
Hello,

You can achieve the mentioned functionality the following way using macros:

TrueValue – “(truevalue)<value>” – Output settings for the positive output of the comparisson

e.g. {%if (UserName == "administrator") { "Yes" } else { "No" }%}

writes Yes if the user is administrator

Another example:

<%# CMS.CMSHelper.CMSContext.CurrentResolver.ResolveMacros("{%if (cmscontext.currentdocumentculture.culturecode == "en-US") { "Ok" } else { "NoOK" }%}")%>

writes OK if the current culture is en-US. For more information please see the following link.

Best regards,
Boris Pocatko

User avatar
Member
Member
eagleag - 3/3/2010 2:39:46 AM
   
RE:If statment in transformation
Hi,
I tried this:

<%# CMS.CMSHelper.CMSContext.CurrentResolver.ResolveMacros("{%if (cmscontext.currentdocument.documentcontent.Featured == "True") { "Ok" } else { "NoOK" }%}")%>

when "Featured" is the field I'm trying to test.
This didnt work.
what is the macro sytax for getting to a specific filed in current document type?

thansk for you help

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 3/9/2010 9:14:18 AM
   
RE:If statment in transformation
Hello,

In that case i would suggest you to use a custom transformation function.

Best regards,
Boris Pocatko

User avatar
Member
Member
Ark_IT - 3/2/2010 1:21:26 PM
   
RE:If statment in transformation
<b><%# Eval("Featured") == "True" ? "Hello" : "bye"%></b>

User avatar
Certified Developer 8
Certified Developer 8
richard - 3/22/2010 6:04:14 PM
   
RE:If statment in transformation
Try

<%# "True".Equals(Convert.ToString(Eval("Featured"))) ? "Hello" : "bye"%>

User avatar
Certified Developer v7
Certified  Developer v7
kmerlihan-ecentricarts - 3/22/2011 9:53:09 PM
   
RE:If statment in transformation
This worked great! Thanks