Sign In

Blog

With the 6.0 beta being out for a couple of days, I thought it was time to take a better look at some of the new features. One feature that I am really looking forward to use is the new K# engine. In this post I will cover a couple of examples using K#.

1. Methods

The newly improved Macro editor not only displays a list of available Macros, but it also shows you a list of methods that you can use. Take for example the GetUserFullName method that takes a User's ID and returns the User's Full Name:

{% GetUserFullName(CurrentUser.UserID) %} 

The macro and it's result are illustrated in the following screenshot:

ksharp_example_1.png

2. foreach loop

K# supports some well known commands like if statements, for loops, while loops and foreach loops. In the example below I loop through all the children of the document root and output every documents name (MenuItemName).

{% ret = ""; foreach(x in RootDocument.Children) { ret += x.MenuItemName} ret %}

ksharp_example_2.png

3. Comments

You can add some comments to your code similar to C#:

{%
   ret = "";

   // Loop through the children
   foreach(x in RootDocument.Children)
   { 
      // Add the MenuItemName
      ret += x.MenuItemName
   } 

   ret
%}


ksharp_example_3.png

4. Lorem Ipsum

Version 6.0 brings you the "Lorem Ipsum" macro! Simply use the following syntax to generate the Lorem ipsum text:

{%LoremIpsum%}

ksharp_example_4.png

5. Transformations

It will be possible to use Macros in transformations if you choose a Macro supporting transformation type like HTML. Known syntaxes like the following will be possible without additional code (CMS.CMSHelper.CMSContext.CurrentResolver.ResolveMacros(string inputText)):

{%NewsTitle%} 

ksharp_example_5.png

That concludes the sneak peek at K#. I hope these examples will give you an idea of what's to come and I am looking forward to provide you with more examples once I can use K# in practise. K# is definitely in my top 3 list of best 6.0 features!
Posted: 22-08-2011 | 0 comments | Filed under: Macro, K#


Here is a quick tip that is useful if you work a lot with widgets in Kentico. You might know that macros are not allowed in the widgets editing form because of security reasons. Luckily for us developers there is a nice little workaround to enable macro resolving in widgets: Add the macro parameter as default value for the field and make sure to uncheck "Display attribute in the editing form". In the screenshot below you can see an example of this where the title querystring is used in the news lists where condition.
Posted: 08-11-2010 | 0 comments | Filed under: Tips and Tricks, Widgets, Macro

Sometimes we get the request to create a menu item that works as a signout button. There are of course several ways to do this. For instance you could create a web part/widget and place it on the page which automatically signs the user out. In this post I will show you a different approach using a custom signout macro.
Posted: 20-08-2010 | 1 comments | Filed under: Macro, API

About me

Jeroen Furst 
  • Facebook
  • LinkedIn
  • RSS
  • Twitter

Kentico DevNet

IBL-Software

Sponsored links

Interview with Kentico

You have an old version of Adobe's Flash Player. Get the latest Flash player.
Kentico blogs and websites
Martin Hejtmanek - Kentico CTO
Thomas Robbins - Kentico product evangelist
Petr Vozak - Kentico team leader
Brian McKeiver - BizStream
Johnny Bubriski - Wakefly, Inc.
Bryan Soltis - Bit-Wizards
Kentico Developer - Reed Business Information
Kentico Solutions - Data, Inc.

My trees

Latest Kentico Knowledge Base Articles

Kentico Developer Posters

Kentico CMS 5.5 Macro Reference