How to add MasterPage properties do change in Admin for they can be visible on MasterPage?

23 views
Skip to first unread message

David Ferreira

unread,
Mar 12, 2019, 1:55:30 PM3/12/19
to KalikoCMS Developer Forum
How to add MasterPage properties do change in Admin for they can be visible on MasterPage?

Like Logo, address, cellphone, etc...

Fredrik Schultz

unread,
Mar 13, 2019, 2:09:28 AM3/13/19
to KalikoCMS Developer Forum
Site wide properties such as logos etc. are preferably handled as properties in the site settings, which are available to edit in admin in the same way as page properties (accessed through the site root in the page tree).

Site settings are created in the same way as page models, you'll find more information here:

You can then access its properties by fetching the site settings in your MasterPage:
var currentSite = SiteFactory.CurrentSite<YourSiteModel>();
var companyName = currentSite.CompanyName.Value;

Hope that helps.

David Ferreira

unread,
Mar 13, 2019, 5:25:09 AM3/13/19
to KalikoCMS Developer Forum
Hi Fredrik Schultz,

I already follow your previous comments on another ocasions, but I didn't fully understand how to implement this.
I've create a SiteSetting with a few properties
In admin area I already can fill those properties.

My concert is, I cannot, I don't know how to catch Those properties in Master Page

You gave me the exemple  "SiteFactory.CurrentSite<YourSiteModel>();", I don't understand what is "YourSiteModel" since it is a MasterPage, I need to implement this on MasterPage or on every Page?

David Ferreira

unread,
Mar 13, 2019, 6:12:27 AM3/13/19
to KalikoCMS Developer Forum
Hi, I've try with a dirty way
In runtime I got the values I want but in Html asp I cannot access tham....Any thoughs?

Runtime (got my values right):

CmsSite obj = SiteFactory.Get(SiteSettings.RootPage);


var Cn = SiteFactory.Get(SiteSettings.RootPage).Property["companyname"];
var cr = obj.Property["copyright"];
var lg = obj.Property["logotipo"];
var scl = obj.Property["showsociallinks"];


Html (cannot get any values): 

<%#KalikoCMS.SiteFactory.Get(KalikoCMS.Configuration.SiteSettings.RootPage).Property["copyright"] %>
<%# KalikoCMS.Configuration.SiteSettings.RootPage %>


Fredrik Schultz

unread,
Mar 13, 2019, 3:17:43 PM3/13/19
to KalikoCMS Developer Forum
In the HTML, are you running your code inside a controller? Otherwise the <%# needs to be replaced by a <%=.

The best way to expose your site properties would be to add a backed property to your master page's code behind (replacing DemoSite with the name of your CmsSite implementation):
        private DemoSite _currentSite;

        public DemoSite CurrentSite {
            get {
                if (_currentSite == null) {
                    _currentSite = SiteFactory.CurrentSite<DemoSite>();
                }

                return _currentSite;
            }
        }

Then you can access your properties, like:
      <div>
          <%=CurrentSite.CompanyName %>
      </div>

In the above example my CmsSite implementation looks like:
    public class DemoSite : CmsSite {
        [Property("Company name")]
        public virtual StringProperty CompanyName { get; set; }
    }

Reply all
Reply to author
Forward
0 new messages