where Logo and Meta fields

45 views
Skip to first unread message

Berkan Arıkan

unread,
Jun 5, 2018, 9:34:48 AM6/5/18
to KalikoCMS Developer Forum
I do not think there are logo and meta fields

Fredrik Schultz

unread,
Jun 5, 2018, 11:13:08 AM6/5/18
to KalikoCMS Developer Forum
The demo is thought an example of a simple implementation, you could easily extend it with a logo as a site property and adding the meta-fields you wish to have to the page models. If you want some starter points on this I would be happy to help.

Berkan Arıkan

unread,
Jun 6, 2018, 4:26:05 AM6/6/18
to KalikoCMS Developer Forum
I am very happy if you help in this matter

Fredrik Schultz

unread,
Jun 11, 2018, 4:29:10 PM6/11/18
to KalikoCMS Developer Forum
Adding a logo

A logo image could be added to the site definition (as it's a global property).

Open Models/DemoSite.cs in the demo project and add the following lines:
[Property("Company logo")]
public virtual ImageProperty CompanyLogo { get; set; }

Open Views/Shared/_Layout.cshtml and add this to render the image:
<a href="~/" class="navbar-brand" title="Demo project">
   @Model.CurrentSite.CompanyLogo.ToHtml()
</a>


Adding meta data to all pages

A good pattern is to create a base page model with common properties, such as meta data, and let all page models inherit this model.

I'm attaching all the modified files to this post for convenience, but this is a quick walk trough:

Add a new model; Models/Pages/PageBase.cs:
namespace DemoSite.Models.Pages {
    using KalikoCMS.Attributes;
    using KalikoCMS.Core;
    using KalikoCMS.PropertyType;

    public class PageBase : CmsPage {
        [Property("Meta description", TabGroup = "SEO")]
        public virtual TextProperty MetaDescription { get; set; }
    }
}

Update all pages to inherit the new page base instead of CmsPage:
...
public class ArticlePage : PageBase, IIndexable {
    ...

The view model needs to change to be based on the new page base model.

Models/ViewModels/IPageViewModel.cs:
public interface IPageViewModel<out T> where T : PageBase {

Models/ViewModels/PageViewModel.cs:
public class PageViewModel<T> : IPageViewModel<T> where T : PageBase {

Open Views/Shared/_Layout.cshtml and change the model and render the new meta property:
@using KalikoCMS.Configuration
@model DemoSite.Models.ViewModels.IPageViewModel<DemoSite.Models.Pages.PageBase>
<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>@Model.CurrentPage.PageName</title>
    <meta name="description" content="@Model.CurrentPage.MetaDescription">
...

You now have the infrastructure to add further meta fields.

Hope that helps!
modified-demo-project-files.zip
Reply all
Reply to author
Forward
0 new messages