Technical support This forum is closed.
Version 1.x > Technical support > if statement inside transformation View modes: 
User avatar
Member
Member
marie - 8/15/2006 3:50:33 PM
   
if statement inside transformation
In the product default transformation I have them uploading 2 images if they have 2 images, but it they don't it will display the image box with the x inside it in IE. How can I put an if statement so that it will only display the second image if there is a second image?

Thanks,
Marie

User avatar
Member
Member
marie - 8/15/2006 4:14:31 PM
   
Re: if statement inside transformation
I figured it out! Thanks.

User avatar
Member
Member
persun - 1/19/2007 4:20:50 PM
   
Re: if statement inside transformation
marie,

Could you describe how you got conditional statements into your transformation?

Thanks

User avatar
Member
Member
persun - 1/19/2007 4:57:59 PM
   
Re: if statement inside transformation
Update!

I tried the following:

<p style="display:<%# (String.IsNullOrEmpty(Eval("SoftwareVersionInstallationPackage").ToString()) ? "none" : "block") %>;">
Installation package: <a href="<%# GetFileUrl("SoftwareVersionInstallationPackage")%>">Download</a>
</p>

It works and satisfies my needs at the moment.

Any ideas how to use if-else statements in the transformation code?

The following does not seem to work:

<%# if(false) { %>Don't show this text<%# } %>

User avatar
Guest
admin - 1/20/2007 5:51:23 PM
   
Re: if statement inside transformation
Hello,

you need to create a custom static function in the ProjectFunctions.cs/vb file. This function will get the value as a parameter and it will return the HTML code based on the provided value(s).

Here's an example:

public static string GetImage( object imageUrl ) {
if (imageUrl == null || imageUrl == "")
{
return "";
}
else
{
return "<img src=\"" + imageUrl + "\" />";
}
}

Best Regards,

User avatar
Member
Member
marie - 1/22/2007 7:09:10 PM
   
Re: if statement inside transformation
Persun,

Here is what I have put in my transformation:

This is the image that will always display::::

<img src="<%# ResolveUrl("~/GetFile.aspx?filepath=" + Kentico.CMS.TreeEngine.Functions.UrlPathEncode(DataBinder.Eval(Container, "DataItem.ProductPhoto"))) %>"/>


This is the image that will display if there is an image in this field:

<asp:Image Runat="server" ImageUrl='<%# ResolveUrl( "~/GetFile.aspx?filepath=" + Kentico.CMS.TreeEngine.Functions.UrlPathEncode(DataBinder.Eval(Container, "DataItem.ProductPhoto2"))) %>' Visible='<%# Kentico.CMS.TreeEngine.Functions.NotEmpty(DataBinder.Eval(Container, "DataItem.ProductPhoto2")) %>'></asp:Image>

Good Luck.

User avatar
Guest
admin - 1/24/2007 10:14:45 AM
   
Re: if statement inside transformation
Hi Marie,

Thank you for posting this tip here.

Best Regards,