Here is an example of the code needed:
Note: this is just a quick example, you may have to modify it or change parts depending on your needs.
Step 1) Register your macro name space
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for BPMacros
/// </summary>
using CMS.Base;
using CMS.MacroEngine;
[Extension(typeof(CustomMacroMethods))]
public class BPMacros : MacroNamespace<BPMacros>
{
}
[MacroNamespaceLoader]
public partial class CMSModuleLoader
{
/// <summary>
/// Attribute class that ensures the registration of custom macro namespaces.
/// </summary>
private class MacroNamespaceLoaderAttribute : CMSLoaderAttribute
{
/// <summary>
/// Called automatically when the application starts.
/// </summary>
public override void Init()
{
// Registers "CustomNamespace" into the macro engine
MacroContext.GlobalResolver.SetNamedSourceData("BPMacros", BPMacros.Instance);
}
}
}
Step 2)Create Macro Method
using CMS;
using CMS.CustomTables;
using CMS.DataEngine;
using CMS.DocumentEngine;
using CMS.EmailEngine;
using CMS.Helpers;
using CMS.MacroEngine;
using CMS.Membership;
using CMS.OnlineForms;
using CMS.SiteProvider;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
[assembly: RegisterExtension(typeof(CustomMacroMethods), typeof(BPMacros))]
/// <summary>
/// Summary description for CustomMacroMethods
/// </summary>
public class CustomMacroMethods : MacroMethodContainer
{
/// <summary>
/// Returns a field for a user depending on the string fieldname passed in
/// </summary>
/// <param name="context"></param>
/// <param name="parameters"></param>
/// <returns></returns>
[MacroMethod(typeof(string), "Returns particular field for specific user", 1)]
[MacroMethodParam(0, "param1", typeof(int), "UserID")]
[MacroMethodParam(1, "param2", typeof(string), "FieldName")]
public static object BPUser(EvaluationContext context, params object[] parameters)
{
int UserID = ValidationHelper.GetInteger(parameters[0], 0);
string returnVal = string.Empty;
UserInfo ui = UserInfoProvider.GetUserInfo(UserID);
if (ui != null)
{
try
{
returnVal = ui.GetValue(ValidationHelper.GetString(parameters[1], "")).ToString();
}
catch (Exception ex)
{
//macro error
}
}
return returnVal;
}
}
Step 3)Call Macro
{% BPMacros.BPUser(53, "FullName")|(identity)GlobalAdministrator%}