Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Transformation If Statement Issue View modes: 
User avatar
Member
Member
vcarter - 9/13/2013 11:31:19 AM
   
Transformation If Statement Issue
I have one page using a Query Data Source and a Basic Uni View to display a formatted list of locations. This list is grouped by country. To facilitate this I used a query to pass a ShowCountry [Int] value into the transformation so the country only displays when it is the first location for that country. This works great.

I have another page, which is the detail for the location that lists the media contacts for that location based on associative region and business unit data. The query is almost identical and the transformation looks like this:

<%if (Convert.ToInt32(Eval("ShowBusiness")) == 1) { %>
<tr>
<th><h3><%# Eval("BusinessUnitName") %></h3></th>
<td>
<%# Eval("FirstName") %> <%# Eval("LastName") %><br />
<%# Eval("Company") %><br />
<%# Eval("Phone") %><br />
<%# Eval("Email") %><br />
<%# Eval("Address") %><br />
<%# Eval("City") %>, <%# Eval("PostalCode") %><br />
<%# Eval("Country") %>
</td>
</tr>
<%} %>
<%else { %>
<tr>
<th> </th>
<td>
<%# Eval("FirstName") %> <%# Eval("LastName") %><br />
<%# Eval("Company") %><br />
<%# Eval("Phone") %><br />
<%# Eval("Email") %><br />
<%# Eval("Address") %><br />
<%# Eval("City") %>, <%# Eval("PostalCode") %><br />
<%# Eval("Country") %>
</td>
</tr>
<%} %>


Now, I can just put the ShowBusiness variable on the page and it is correct(first element is 1 all the rest are 0).

The problem is that when it is 1, even though the record is showing on page, the if statement is not evaluating. Is there a syntax difference between a uni view and a repeater when it comes to transformations? My uni view uses a head/foot transformation due to the display requirements. But for this page, that was not necessary so I just went with a single transformation, using content before/after to create the container. Everything displays correctly but my conditional criteria is not being met when it is a 1 for some reason.

Any thoughts?

User avatar
Kentico Support
Kentico Support
kentico_janh - 9/15/2013 4:56:21 AM
   
RE:Transformation If Statement Issue
Hello,

Yes, there is a difference between those two transformations, because in your universal viewer you are using probably the Text/XML transformation where this kind of if statement is allowed. In ASCX transformation, you need to use the IfCompare function instead. So the trasformation would look like this:

<tr>
<th><h3><%# IfCompare(Eval("ShowBusiness"),1," ",Eval("BusinessUnitName")) %></h3></th>
<td>
<%# Eval("FirstName") %> <%# Eval("LastName") %><br />
<%# Eval("Company") %><br />
<%# Eval("Phone") %><br />
<%# Eval("Email") %><br />
<%# Eval("Address") %><br />
<%# Eval("City") %>, <%# Eval("PostalCode") %><br />
<%# Eval("Country") %>
</td>
</tr>


Or you can change the transformation type to Text/XML and update your transformation to this one below:

{% if (ShowBusiness == 1) { ResolveMacros("\r\n<tr>\r\n<th><h3>{%BusinessUnitName%\}</h3></th>\r\n<td>\r\n  {%FirstName%\} {%LastName%\}<br />\r\n  etc.\r\n</td>\r\n</tr>\r\n")} %}


Best regards,
Jan Hermann

User avatar
Member
Member
vcarter - 9/16/2013 1:00:59 PM
   
RE:Transformation If Statement Issue
Thank you, that worked!