Created
September 20, 2023 18:43
-
-
Save keyan1603/a751b13d955bf78cc59003b4ad9f2b8a to your computer and use it in GitHub Desktop.
Sitecore SXA – To get Site Settings for a Site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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