Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Transformation logic automatically closes div View modes: 
User avatar
Member
Member
Jerreck - 1/27/2014 11:57:35 AM
   
Transformation logic automatically closes div
I have the following ternary operator in an ASCX transformation:
<%# DataItemIndex == 0 ? "<div>":"" %>

The expression resolves properly - it places a div at it's appropriate position in the transformation if this is the first item in the index of the repeater.

However, it also automatically closes the div after the last item in the index. I'm not sure why it's doing this, but I need it to just place the opening div and nothing more. I'm going to tell it later when to close.

I used almost the exact same line of code in a Text/XML transformation and it worked perfectly. I'm guessing there's some ASP.NET thing happening here that's causing it to close? If so, what do I have to do to tell it "hey, stop that"?

User avatar
Certified Developer 10
Certified Developer 10
josha-bpstudios - 1/27/2014 12:06:56 PM
   
RE:Transformation logic automatically closes div
In the design tab go to the configuration of your repeater. Check the output filter settings on your repeater webpart. There may be a setting on there that will stop this behavior.

User avatar
Member
Member
Jerreck - 1/27/2014 1:57:20 PM
   
RE:Transformation logic automatically closes div
I toggled all the output filters. No dice :(

Good idea, though. Thank you :)

User avatar
Certified Developer 10
Certified Developer 10
josha-bpstudios - 1/27/2014 2:18:16 PM
   
RE:Transformation logic automatically closes div
Have you checked your settings in sitemanager? Under Settings -> System -> Output Filter. Maybe try to put your page that you are working in the "Excluded output form filter URLs" field.

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 1/27/2014 2:35:05 PM
   
RE:Transformation logic automatically closes div
Jerreck wrote: However, it also automatically closes the div after the last item in the index. I'm not sure why it's doing this, but I need it to just place the opening div and nothing more. I'm going to tell it later when to close.
Are you looking in developer tools (F12) or are you viewing the source of the page? In order to properly see whats being rendered you need to view the source, dev tools or F12 in most browsers will "auto" close the open tag in most instances. I do this all the time and have no problem with it whatsoever.

User avatar
Member
Member
Jerreck - 1/28/2014 8:47:21 AM
   
RE:Transformation logic automatically closes div
Ah, the tags aren't being closed in the source, thank you. However, they're still closed by the browser even though I'm loading closing tags at the end of the transformation. Here's the rest of the transformation:
<!-- Creates the very first row -->
<%# DataItemIndex == 0 ? "<div class=\"row\">" : "" %>
<div class="content"><!--Begin of item-->
<%# Eval("Some_Value1")%>
<%# Eval("Some_Value2")%>
<%# Eval("Some_Value3")%>
</div><!--End of item-->
<!-- End last row and create a new row -->
<%# (DataItemIndex + 1) % 3 == 1 ? "</div><div class=\"row\">" : "" %>

Basically, I'm making rows for a grid of items and starting a new row if the item's index is divisible by 3 (so rows of 3).

I've solved the issue by switching to a text/XML transformation (which I think is faster than ASCX anyway), but I'm still not sure why the tags would be auto-closed for ASCX and not Text/XML.

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 1/29/2014 6:34:49 AM
   
RE:Transformation logic automatically closes div
Based on your code, I don't think you have your closing MOD right. The code I show below creates rows of 3 items.

I've got a Three Up transformation on a custom doc type and it works perfect. This creates the opening tag for a row of 3
<%# ((DataItemIndex % 3 == 0) ? "<div class=\"row\">" : "" ) %>
And this closes it off
<%# (DataItemIndex % 3 == 2 || DataItemIndex == DataRowView.DataView.Count - 1 ? "</div>" : "") %>
The key to the last part is the MOD and looking for the last item in the DataView. If you only have 2 items and not 3, you won't get a closing tag.

User avatar
Member
Member
Jerreck - 1/28/2014 8:48:50 AM
   
RE:Transformation logic automatically closes div
[edited] Check the previous post.

User avatar
Member
Member
Jerreck - 1/28/2014 8:51:41 AM
   
RE:Transformation logic automatically closes div
Oh, and happy double-post day.