Sometimes there's a need to set site wide properties, not connected to a particular page but rather the site itself. This is done by creating site settings. It can also be used to control sort order or available page types at root level.
Site settings are created by inheriting the class CmsSite
and decorating the new class with the SiteSettings
attribute. In the SiteSettings
attribute you can set sort order and allowed page types for the root level of the site.
Properties are declared in the same way as in page types, by creating virtual properties out of property types and decorating them with the proper attribute.
namespace DemoSite.Models { using KalikoCMS.Attributes; using KalikoCMS.Core; using KalikoCMS.PropertyType; using Templates.Pagetypes; [SiteSettings(AllowedTypes = new[] { typeof(NewsListPageType), typeof(StartPageType), typeof(ProductListType), typeof(ArticlePageType) })] public class Site : CmsSite { [Property("Company")] public virtual StringProperty CompanyName { get; set; } [Property("Show social links")] public virtual BooleanProperty ShowSocialLinks { get; set; } } }
The site settings can be loaded in code by calling SiteFactory.CurrentSite<T>()
with the created CmsSite
class as T. A proxy for T are returned and can be used to access the defined properties:
var currentSite = SiteFactory.CurrentSite(); var companyName = currentSite.CompanyName.Value;
Only one instance based on CmsSite
can be created in each project.