Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Custom macro for "Select top N documents" View modes: 
User avatar
Member
Member
pt - 4/23/2011 6:24:15 AM
   
Custom macro for "Select top N documents"
Hi,
New user here. I'm trying to use a custom macro for a "Latest News" web part's "Select top N documents" property. My syntax for for adding the custom macro is:

<%# MorphotekMacroManager.GetNewsCountToDisplay(3, 3) %>

which is a static method of a static class in a c# file in the App_Code directory of my solution. I know the macro call works - I placed it in the transformation for the web part and get the expected result. But when I place it in the "Select top N documents" property it apparently fails because I get the entire list of news items and not the number that should be returned by the method. From what I've read this seems like it should work. Can anyone provide some insight on what I'm doing wrong?
Many thanks,
Paul

User avatar
Member
Member
pt - 4/27/2011 10:05:33 AM
   
RE:Custom macro for "Select top N documents"
A little help from the Kentico folks would be nice. I've scoured the forums and documentation and can't see what I'm doing wrong. Would be nice to know if this macro feature is not supported for this repeater property.

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 4/27/2011 3:44:28 PM
   
RE:Custom macro for "Select top N documents"
Hello,

regarding the Custom macro, you need to create it different way in ~/App_Code/Global/CMS/CMSCustom.cs class and call different way as described in our Developer's Guide: Macro expressions

Hope this helps.

Best regards

Ondrej Vasil

User avatar
Member
Member
pt - 4/27/2011 4:16:55 PM
   
RE:Custom macro for "Select top N documents"
Thank you Ondrej for the reply. I have tried the custom macro approach but have not been successful.

My macro code is (for testing I'm just returning a fixed number)
...
case "setnewsitemcounttodisplay":
match = true;
result = "4";
break;
...

My call to this macro in the web part editor is:
{% ProcessCustomMacro("SetNewsItemCountToDisplay", "") %}

Apparently it always fails because my repeater returns the entire set of records.

Is there a syntax problem here?

Thanks,
Paul

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 4/28/2011 1:03:09 AM
   
RE:Custom macro for "Select top N documents"
Hello,

That exact macro works for me. Actually, the Top N property accepts the integer value, therefore you need to use the macro editor (a gray triangle) and insert your macro expression. Give it a shot please.

Best regards
Ondrej Vasil

User avatar
Member
Member
pt - 4/28/2011 5:29:58 AM
   
RE:Custom macro for "Select top N documents"
I truly appreciate the guidance Ondrej but this is still not working. I used the gray triangle, selected a custom macro, entered my expression ('SetNewsItemCountToDisplay') and pressed Insert Macro (the code then appeared in the editor) and then pressed OK. Is there a way for me to verify that the macro is even being called on my server?
Thanks,
Paul

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 4/29/2011 3:15:25 AM
   
RE:Custom macro for "Select top N documents"
Hello,

that's strange. Therefore, I'd like to ask you to check and perform the following things:

1) Don't you use the Query Repeater webpart (Repeater with custom query)? I can see that you are using the Latest News webpart, but just to be completely sure :-)

2) Enable SQL debug by adding the <add key="CMSDebugEverything" value="true"/> key to the web.config file and go to the Site Manager -> Administration -> System -> Debug -> SQL Queries and check the actual Repeater query. Does it contain correct TopN condition?

3) Put a breakpoint to your custom macro to see, whether the application steps into it.

Please let me know your findings.

Best regards
Ondrej Vasil

User avatar
Member
Member
pt - 4/29/2011 6:32:18 AM
   
RE:Custom macro for "Select top N documents"
Thank you Ondrej for your help with our problem. We had to abandon the custom macro approach for the web part's property due to our project time line. We opted for using a custom function within the transformation. It was not our preferred solution but we simply were unable to invest anymore time in the custom macro. Thanks again, Paul