Access custom fields through the SiteMapNodes
You can access the custom fields using the PageSiteNode object. This can be useful when working with a custom widget that is placed on a page.
Use the following code sample:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Sitefinity.Model;
using Telerik.Sitefinity.Web;
namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Pages.CustomFields
{
public partial class PagesCustomFieldsSnippets
{
public void GetCustomFieldForPageThroughSiteMapNode()
{
//use SiteMapBase.GetCurrentNode() to get the current node
var provider = SiteMapBase.GetCurrentProvider() as SiteMapBase;
var node = provider.FindSiteMapNodeFromKey("283D7E4A-61BD-62C5-8058-FF00004169B7") as PageSiteNode;
//get visits count
var visitsCount = (decimal)node.GetCustomFieldValue("VisitsCount");
//get taxonomies
var tagIds = (IList<Guid>)node.GetCustomFieldValue("Tags");
//get related image
var image = ((IEnumerable<IDataItem>)node.GetCustomFieldValue("HelpImage")).FirstOrDefault();
}
}
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
Foundations of Sitefinity ASP.NET Core Development
The free on-demand video course teaches developers how to use Sitefinity ASP.NET Core and take advantage of its decoupled architecture and modern development model.