Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Strange Transformation conditional statement issue View modes: 
User avatar
Member
Member
brandonm-salespad - 4/25/2012 3:47:29 PM
   
Strange Transformation conditional statement issue
The issue that I'm having is while trying to evaluate a field in a transformation.

This is the code that I think should work, but doesn't.

<article name='<%# Eval("Title")%>' class='<%# (DataItemIndex != 0) ? "hidden" : ""%>' hasSlideShow='<%# Eval("HasSlideShow")%>'>
<% if ( Convert.ToString(Eval("HasSlideShow")) == "Yes") { %>
<script>var photoViewer = new ProductPhotoViewer('<%# Eval("Title")%>');
<cms:CMSRepeater OrderBy="NodeOrder" runat="server" ClassNames="custom_1023.product_slide_slideshow_slide" TransformationName="custom_1023.product_slide_slideshow_slide.Default"></cms:CMSRepeater>
</script>
<% } %>
<%# Eval("InnerHTML")%>
</article>


More specifically it's this line that should evaluate as true, but does not.
<% if ( Convert.ToString(Eval("HasSlideShow")) == "Yes") { %>


As you can see on the first line, I put evaluated this into an attribute on the <article> to see what it says, and sure enough it outputs as "Yes" when I believe it should.

As far as I can tell it shouldn't be an issue with my if statement because if I do
<% if ( DataItemIndex == 0) { %>

It does what I want as well.

Thanks in advance for the help.

User avatar
Kentico Support
Kentico Support
kentico_janh - 4/26/2012 1:28:12 AM
   
RE:Strange Transformation conditional statement issue
Hello,

May I ask you, what type is your HasSlideShow field?

What do you get if you try to resolve only following line?

<%# Eval("HasSlideShow").ToString() %>


Best regards,
Jan Hermann

User avatar
Member
Member
brandonm-salespad - 4/26/2012 7:26:41 AM
   
RE:Strange Transformation conditional statement issue
Here are my field settings. The type is currently TEXT but originally I was attempting with a Boolean and then an Integer but couldn't get past this so I kept trying new things until now I'm here.

User image

Here's the code evaluation you requested and the output (via Firefox).
Larger So You can See Text
User image
User image

As you can see, you're requested code evaluation outputs the string "Yes" (which I would expect).

User avatar
Kentico Support
Kentico Support
kentico_janh - 4/26/2012 8:01:53 AM
   
RE:Strange Transformation conditional statement issue
Hello,

The problem is, that you can use transformation functions only in the <%# function() %> format, so that is the reason why the Eval() function is not resolved in your if statement. Please use the IfComapre() transformation method instead:

IfCompare(object value, object comparableValue, object falseResult, object trueResult)

->

<%# IfCompare(Eval("HasSlideShow"), "Yes", "false", "true") %>


Best regards,
Jan Hermann

User avatar
Member
Member
brandonm-salespad - 4/26/2012 8:54:20 AM
   
RE:Strange Transformation conditional statement issue
Thank you for the help. While this does work as far getting my code to not break, it unfortunately still does not quite fit my intended goal. The issue is that I have a block of transformation code that I want to only run when this evaluates as true. This form with the # character at the start does not allow me to have open and close tags with code in the middle. You can see my initial code post for an example of what I mean.

Is there any way that I can have transform code only show when this evaluates as true?

User avatar
Kentico Support
Kentico Support
kentico_janh - 4/27/2012 2:25:40 AM
   
RE:Strange Transformation conditional statement issue
Hello,

I see, then you would need to write your own custom function to that transformation, which renders HTML code of your nested repeater and returns it as a string:

<%# IfCompare(Eval("HasSlideShow"), "Yes", "", MyFunctions.getCode()) %>


Best regards,
Jan Hermann

User avatar
Member
Member
brandonm-salespad - 5/3/2012 1:50:46 PM
   
RE:Strange Transformation conditional statement issue
Ok so I've got the code pulling from my new custom function, but I"m not sure how to render the HTML code from the nested repeater from within that function. Could you please point me in the right direction for how to generate that HTML from the nested repeater? I would normally have just used the <cms:CMSRepeater> tag, but it doesn't render when I just output that from the function. I"m guessing I have to somehow access the children of this element and call their transform function. I have no idea how to approach that though.

User avatar
Kentico Support
Kentico Support
kentico_janh - 5/9/2012 1:27:08 AM
   
RE:Strange Transformation conditional statement issue
Hello,

Please copy and use following code in your custom function:

Page pageHolder = new Page();

CMSRepeater rep = (CMSRepeater)pageHolder.LoadControl(typeof(CMSRepeater), null);

// set your own parameters
rep.ClassNames = "cms.menuitem";
rep.Path = "./%";
rep.TransformationName = "cms.menuitem.default";

pageHolder.Controls.Add(rep);

StringWriter output = new StringWriter();
HttpContext.Current.Server.Execute(pageHolder, output, false);

return output.ToString();


Best regards,
Jan Hermann

User avatar
Member
Member
brandonm-salespad - 5/9/2012 2:20:17 PM
   
RE:Strange Transformation conditional statement issue
Wow that is eye opening. Thanks so much for that. It has solved a number of complications I'm having. Case closed.