Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Transformations - IfEmpty statement View modes: 
User avatar
Member
Member
gavin-wdm.com - 11/11/2010 10:19:38 PM
   
Transformations - IfEmpty statement
Hi,

I want to show some specific code if a value is set, else show nothing.

I have used this before, however it was only to show a heading and it worked fine.

Now I need to show a list item, an a tag and an value from a field.

Below is my code:

<%# IfEmpty(Eval("sciBuyOnline"), "", "<li><a href="<%# Eval("sciBuyOnline") %>" title="Buy <%# Eval("sciName") %> Online Now!">Buy Now</a></li>") %>


In summary, if the field 'sciBuyOnline' is empty, it should show nothing else it should output the following code:
<li><a href="<%# Eval("sciBuyOnline") %>" title="Buy <%# Eval("sciName") %> Online Now!">Buy Now</a></li>


The error I am getting is this:

[CMSDataProperties.LoadTransformation]: http://server/CMSTransformations/a0e429b5-9878-481f-838e-4df23bea2557/custom/softwarecatalogueitem/default.ascx(27): error CS1040: Preprocessor directives must appear as the first non-whitespace character on a line


Does this mean I cannot use whitespace at all in my outputted code? Please help me :)

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 11/12/2010 4:19:09 AM
   
RE:Transformations - IfEmpty statement
Hi Gavin,

Could you please try to use following transformation:


<%# IfEmpty(Eval("yourcolumn1"), "", "<li><a href=\"" + Eval("yourcolumn2") +"\" title=\"Buy "+ Eval("yourcolumn3")+ " Online Now!\">Buy Now</a></li>") %>


Best regards,
Ivana Tomanickova

User avatar
Member
Member
afique-resolvtech - 11/20/2013 7:55:10 PM
   
RE:Transformations - IfEmpty statement
Hi Ivana,

How about if I wanted it displays nothing. I just want to leave it blank for empty value in my column.

Could you help me?

Thanks

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 11/21/2013 1:12:06 AM
   
RE:Transformations - IfEmpty statement
Hi Afique,

Your question is already answered in http://devnet.kentico.com/Forums.aspx?forumid=70&threadid=41956

Also this post is 3 years old so please when you create a new topic wait for us to answer your initial question first.

Kind regards,
Richard Sustek