Kentico Repeater HTML Properties showing with sele

2019-07-07 19:42发布

问题:

My HTML envelope wraps my repeater transformation in a TABLE tag. Without using JS, how do i ensure this HTML isn't visible for the selected transformation. I have no objections to have a template for the selected transformation data, just unsure how to do that.

Here is my Transformation:

<tr>
   <td><%# FormatDate(Eval("Date")) %></td>
   <td><a href="<%# GetDocumentUrl() %>"><%# Eval("Subject") %></a></td>
   <td><%# Eval("From") %></td>
</tr>

And this is my selected transformation:

<section id="memoDetail">
  <h1>Memorandum</h1>
  <ul id="memoHeader">
   <li><span class="headerLabel">To:</span> <%# Eval("To") %></li>
   <li><span class="headerLabel">From:</span> <%# Eval("From") %></li>
   <li><span class="headerLabel">Subject:</span> <%# Eval("Subject") %></li>
   <li><span class="headerLabel">Date:</span> <%# Eval("Date") %></li>
  </ul>
  <div id="memoDetails"><%# Eval("Details") %></div>
</section>

回答1:

Consider moving your table tags from the html envelope and conditionally rendering them inside your transformation like this:

// If this is the first item in the repeater, open the table tag
<%# DataItemIndex == 0 ? "<table>" : "" %>

  // your trasformation code

// if this is the last item in the repeater, close the table tag
<%# DataItemIndex + 1 == DataItemCount ? "</table>" : "" %>

This will prevent them from appearing in your selected item transformation since it's a completely different transformation.

You may have to place the DataItemIndex and DataItemCount properties within an Eval() method. It's been awhile since I've worked with ASCX transformations.

Edit: Looks like you can now use the IsFirst() and IsLast() methods within ascx transformations:

<%# IsFirst() ? "<table>" : "" %>

// transformation code

<%# IsLast() ? "</table>" : "" %>


回答2:

If the list and detail page type are different. Another solution is to use a macro in html envelope property of the repeater. For example, if the page type of the list is CMS.MenuItem, the property should look like this:

{% ClassName == "CMS.MenuItem" ? "<table>" : "" #%}


标签: kentico