Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > k# syntax help View modes: 
User avatar
Certified Developer 12
Certified Developer 12
chetan2309-gmail - 10/18/2013 7:20:36 AM
   
k# syntax help
Hi All,

I need a small syntax help for K#. This is my requirement. I have a glossary section With "Letter" and "Definition". I am rendering this in a transformation to display using ul, li elements.

My current transformation is like this
<%# ((DataItemIndex % 5 == 0) ? "<ul>" : "") %>
<li alphabet="<%# Eval("Index") %>" class="terms">
<a href="javascript:void(0)" ><%# Eval("Term") %></a>
</li>
<div style="display:none" term="<%# Eval("Term") %>" class="termDef">
<%# Eval("Definition") %></div>
<%# ((DataItemIndex % 5 == 4 || DataRowView.DataView.Count -1 == DataItemIndex) ? "</ul>" : "") %>

Now instead grouping in a set 5 and doing css stuff to align the UI, I wish to group them by "Alphabet" so that all <li> which belongs to a particular "alphabet" becomes part of a same <ul>

Thanks in Anticipation,
Chetan

User avatar
Member
Member
vcarter - 10/18/2013 10:18:54 AM
   
RE:k# syntax help
<ul>
<li alphabet="1"></li>
<li alphabet="1"></li>
<li alphabet="1"></li>
</ul>

<ul>
<li alphabet="2"></li>
<li alphabet="2"></li>
<li alphabet="2"></li>
</ul>

Correct?

The only way I have been able to achieve this in similar situations is to pull my data using a custom query and add a "1st" tag to the data. Then I key my groupings off of the "1st" value. If we had the ability to set iterative values in the transformation this would not be necessary, but to my knowledge, there is no way to add a count or a check value that is available to the next iteration of the repeater loop.

User avatar
Certified Developer 12
Certified Developer 12
chetan2309-gmail - 10/18/2013 10:56:34 AM
   
RE:k# syntax help
Yup this is what I want to achieve. Yup lack of this temporary variable is a great drawback and it becomes double when you don't know much .NET

So any idea who you dealt with that?

Thanks,
Chetan

User avatar
Member
Member
vcarter - 10/18/2013 11:47:07 AM
   
RE:k# syntax help
The only solution I have used involves creating a custom query, pushing my results into a temp table and adding a grouping variable. Then I just use that variable to separate my content in the transformation. Probably not the only way, but it has worked well for me. It does require SQL knowledge though.

User avatar
Certified Developer 13
Certified Developer 13
kentico-jx2tech - 10/18/2013 2:29:15 PM
   
RE:k# syntax help
Are your glossary items documents or a custom table??

User avatar
Certified Developer 12
Certified Developer 12
chetan2309-gmail - 10/18/2013 3:11:25 PM
   
RE:k# syntax help
Document type

User avatar
Certified Developer 13
Certified Developer 13
kentico-jx2tech - 10/18/2013 3:39:18 PM
   
RE:k# syntax help
Consider the following k# using the cms.News doctype in the Corporate example site for inspiration. It can be placed in a static text web part.
{% 
MyNews = Documents["/News"].Children.ClassNames("CMS.News").OrderBy("NewsTitle").WithAllData;
MyLetter = "first";

foreach(MyNewsItem in MyNews) {
if (MyNewsItem.NewsTitle.Substring(0,1) != MyLetter) {
println((MyLetter == "first") ? "<h2>" + MyNewsItem.NewsTitle.Substring(0,1) + "</h2><ul>" : "</ul><h2>" + MyNewsItem.NewsTitle.Substring(0,1) + "</h2><ul>");
MyLetter = MyNewsItem.NewsTitle.Substring(0,1);
}

println("<li>" + MyNewsItem.NewsTitle + "</li>");

}

println("</ul>");
%}

That will produce the following output...
<h2>A</h2>
<ul>
<li>Apple iPad 2 In Stock</li>
</ul>
<h2>C</h2>
<ul>
<li>Community Website Section</li>
<li>Company Growth Exceeds Expectations</li>
</ul>
<h2>N</h2>
<ul>
<li>New Consulting Services</li>
</ul>