Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Accessing Custom Settings in Macros View modes: 
User avatar
Member
Member
tj-norex - 7/10/2012 2:48:36 PM
   
Accessing Custom Settings in Macros
I've created a custom setting (in Site Manager > Development > Custom settings) called TwitterURL, now I'm looking to pull that in to a static html block with a macro and cannot seem to find any documentation.

Any ideas as to how I can access this setting with a macro?

Thanks

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 7/10/2012 3:39:46 PM
   
RE:Accessing Custom Settings in Macros
You can create a custom macro method with something like this in it
public string GetSiteSetting(string settingKey)
{
return SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + "." + settingKey)
}

I don't know if there are any built in macro methods for this, but I don't think there are.

If you don't know how to add custom macro methods, look in /app_code/samples/classes/custommacromethods.cs for an example and /app_code/samples/modules/samplemacromodule.cs to see how to load them.

I find the custom macro methods to be extremely useful.

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 7/10/2012 3:46:18 PM
   
RE:Accessing Custom Settings in Macros
Here is what you can put in the CustomMacroMethods.cs file

Put this in the RegisterMethods() Block:

MacroMethods.RegisterMethod("GetSiteSetting", GetSiteSetting, typeof(string), "returns value of site setting with specified setting key", null, 1, new object[,] { { "type", typeof(string), "The settings key name. " }, { "siteName", typeof(string), "The site name. If this parameter is omitted, the value of CMSContext.CurrentSiteName will be used" } }, null);


add these methods to the class

public static string GetSiteSetting(string settingKey, string siteName)
{
return SettingsKeyProvider.GetStringValue(String.Format("{0}.{1}", siteName, settingKey));
}
public static object GetSiteSetting(params object[] parameters)
{
switch (parameters.Length)
{
case 1:
return GetSiteSetting(ValidationHelper.GetString(parameters[0], String.Empty), CMSContext.CurrentSiteName);
case 2:
return GetSiteSetting(ValidationHelper.GetString(parameters[0], String.Empty), ValidationHelper.GetString(parameters[1], String.Empty));
default:
break;
}
return null;

}

User avatar
Member
Member
tj-norex - 7/11/2012 7:52:36 AM
   
RE:Accessing Custom Settings in Macros
Thanks, I thought this may be the case. I have written a few custom macros, I just wanted to make sure there was no existing functionality before I went and did this. No point reinventing the wheel.