Skip to content

Instantly share code, notes, and snippets.

@keyan1603
Created September 20, 2023 18:43
Show Gist options
  • Save keyan1603/a751b13d955bf78cc59003b4ad9f2b8a to your computer and use it in GitHub Desktop.
Save keyan1603/a751b13d955bf78cc59003b4ad9f2b8a to your computer and use it in GitHub Desktop.
Sitecore SXA – To get Site Settings for a Site
public static T GetValueFromSiteSettings<T>(IMvcContext mvcSiteContext, string TenantSiteSettingsTemplateId)
{
var query = "/sitecore/content//*[@@ID='" + mvcSiteContext.GetRootItem<Item>().ID + "']/*[@@templateId='" + TenantSiteSettingsTemplateId + "']";
var settings = mvcSiteContext.SitecoreService.Database.SelectSingleItem(query);
if (settings == null)
{
return null;
}
return mvcSiteContext.SitecoreService.GetItem<T>(settings);
}
// If required can use below code for line number 3
var query = "/sitecore/content//*[@@ID='" + mvcSiteContext.GetRootItem<Item>().ID + "']/Settings";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment