I've been trying to get a custom macro to work with Kentico 6.0.25 but I can't seem to find how.
I've code this in a .cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CMS.SettingsProvider;
using CMS.GlobalHelper;
/// <summary>
/// Summary description for CMSModuleLoader
/// </summary>
public partial class CMSModuleLoader
{
private class CLCustomMacroLoaderAttribute : CMSLoaderAttribute
{
/// <summary>
/// Registers module methods.
/// </summary>
public override void Init()
{
// -- Custom macro methods
CLCustomMacroMethods.RegisterMethods();
}
}
}
public static class CLCustomMacroMethods
{
/// <summary>
/// Registers all blog methods to macro resolver.
/// </summary>
public static void RegisterMethods()
{
MacroMethods.RegisterMethod(
"GetTheme", // 1. parameter: Method name.
GetTheme, // 2. parameter: Method delegate (wrapper method).
typeof(string), // 3. parameter: Return type of the method.
"Returns the site theme", // 4. parameter: Comment for the method used in macro autocompletion.
null, // 5. parameter: Formatting string for "human readable" translation of the method call (optional, you do not have to specify).
0, // 6. parameter: Minimal number of parameters needed to call the method (mimimal overload).
null, // 7. parameter: Parameter definition in format {{name, type, comment}, {name, type, comment}, ...}.
null, // 8. parameter: A list of special parameters needed to be supplied by resolver (these parameters are automatically passed by MacroResolver as the first parameters to the wrapper method).
new List<Type>() { typeof(string) } // 9. parameter: List of types for which the method is applicable (set to null for all types to be allowed). When not specified, the method will be applicable to the type of its first parameter.
);
}
public static string GetTheme()
{
return Utils.SiteUtils.GetTheme();
}
public static object GetTheme(params object[] parameters)
{
switch (parameters.Length)
{
default:
return GetTheme();
}
}
}
I was wondering how can I make this work with a macro like this:
{% GetTheme() %}
The method has 0 parameter. It just returns the value that another method returns. I want to use it similar to old K5.5 macros (such as
{% ProcessCustomMacro("gettheme", "") %} ).
What's wrong with the code I have?