Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > conditional statement in transformation View modes: 
User avatar
Member
Member
tjadoon-gmail - 9/8/2010 11:03:22 AM
   
conditional statement in transformation
Hi,

How can i put conditonal statement in a transformation for my document type? FirstName is the document type attribute below.
<% if (Eval("FirstName") == "MyName") { %>
<br />
Custom Text
<br />
Custome Text
<% } %>

Thanks

User avatar
Member
Member
francis.harvey-irisco - 9/8/2010 2:53:56 PM
   
RE:conditional statement in transformation
you can use static class/function in transformation, just put it in APP_CODE
public static class MyFunctions
{
public static string WriteURLLink(object url, object name)
{
if(url.ToString() == "")
return name.ToString();
else
return "<A href=\"" + url.ToString() + "\">" + name.ToString() +"</A>";
}
}

User avatar
Member
Member
tjadoon-gmail - 9/9/2010 7:31:35 PM
   
RE:conditional statement in transformation
in my transformation i have this but the link doesnt show.
<%# MyFunctions.WriteURLLink(Eval<string>("Link")) %>

a valid link gets returned back to the transformation.

User avatar
Member
Member
kentico_michal - 9/10/2010 3:24:39 AM
   
RE:conditional statement in transformation
Hi,

Could you please describe in more detail what are you trying to achieve.

Would it be possible to post here your WriteURLLink method?

Please find more information about creating custom function in transformation at Developers guide
http://devnet.kentico.com/docs/devguide/index.html?adding_custom_functions_to_transformations.htm

Best regards,
Michal Legen

User avatar
Member
Member
tjadoon-gmail - 9/10/2010 10:00:47 AM
   
RE:conditional statement in transformation
Transformation:
<%@ Register TagPrefix="cms" TagName="Media" Src="~/CMSInlineControls/MediaControl.ascx" %>

showing the media image tag here:
<%# MyFunctions.GetMediaImgTagOnly(Eval<string>("Photo"), "about-peopleImage") %>

Functions:
private static readonly string MySiteCodeName = "/MyCmsSite";

/// <see cref="http://devnet.kentico.com/Forums/f45/t16108/Media-Selection-Url-Issue.aspx"/>
public static string GetMediaUrl(object txtValue)
{
string aliasRemovedUrl = String.Empty;
if (!(txtValue == null | txtValue == DBNull.Value))
{
aliasRemovedUrl = txtValue.ToString().Replace(MySiteCodeName, "~");
}

return aliasRemovedUrl;
}

/// <see cref="http://devnet.kentico.com/Forums/f45/t16228/conditional-statement-in-transformation.aspx"/>
public static string GetMediaImgTagOnly(object txtImage, object cssClass)
{
string mediaImgTag = String.Empty;
if (!(txtImage == null | txtImage == DBNull.Value | String.IsNullOrEmpty(txtImage.ToString())))
{
//work with the image
mediaImgTag = "<cms:Media id=\"mediaImageID\" runat=\"server\"";
if (!(cssClass == null | cssClass == DBNull.Value | String.IsNullOrEmpty(cssClass.ToString())))
{
mediaImgTag += " class=\"" + cssClass + "\"";
}
mediaImgTag += " Url=\"" + GetMediaUrl(txtImage) + "\" />";
}
return mediaImgTag;
}

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 10/5/2010 10:26:53 AM
   
RE:conditional statement in transformation
Hi,

have you found a solution to this issue?

Also, have you tried to verify if the result of Eval method is correctly passed to your custom function?
There could be a limitation that the methods and their parameters were resolved at the same time, causing the wrong parameter being passed into the custom function.

Thank you in advance for information.

Regards,
Zdenek

User avatar
Member
Member
tjadoon-gmail - 10/5/2010 6:12:12 PM
   
RE:conditional statement in transformation
I am using image in the transformation and making the visible attribute true or false now.
visible="<%# MyFunctions.isImage(Eval<string>("Photo"))%>"