Configure the project to display content

This page is part of a series you should follow sequentially from beginning to end. Go to the first step.

You have created a page content type – Landing page – with a field that allows for referencing another reusable content type – Slogan. The next step in line with our recommended practices is to create a Page template.

But first, let’s get some necessary configuration tasks out of the way.

Enable Content tree-based routing and Page Builder

Page templates require the following features to be enabled:

  • Page Builder allows editors to design web pages using drag-and-drop widgets, templates, and other configurations.
  • Content tree-based routing creates URLs for web pages based on their position in the content tree and automatically handles requests to those URLs.

When you run your Kickstart.Web project, you see a default message rendered on the screen:

The Kickstart.Web site has not been configured yet.

Right now, this message displays for any requests to the application to prevent errors. You need to remove the line of code that renders this message; otherwise, no pages will be accessible.

Open the Program.cs file in your Kickstart.Web project and remove or comment out this line of code:

C#
Program.cs

app.MapGet("/", () => "The Kickstart.Web site has not been configured yet.");

Now you can enable the Page Builder and Content tree-based routing in your middleware pipeline.

Un-comment the lines calling UsePageBuilder and UseWebPageRouting from the features collection passed to builder.Services.AddKentico.

C#
Program.cs

...
// Enable desired Kentico Xperience features
builder.Services.AddKentico(features =>
{
    features.UsePageBuilder();
    // features.UseActivityTracking();
    features.UseWebPageRouting();
    // features.UseEmailStatisticsLogging();
    // features.UseEmailMarketing();
});
...

Add using directives for Kentico.PageBuilder.Web.Mvc and Kentico.Content.Web.Mvc.Routing to resolve errors.

C#
Program.cs

using Kentico.Content.Web.Mvc.Routing;
using Kentico.PageBuilder.Web.Mvc;
...

Provide PageBuilderOptions with the Landing page content type name to the UsePageBuilder method – add using Kickstart to resolve errors.

Use the CONTENT_TYPE_NAME constant from the generated class to access the content type identifier.

C#
Program.cs

...
using Kickstart;
...
builder.Services.AddKentico(features =>
{
    features.UsePageBuilder(new PageBuilderOptions {
        ContentTypeNames = new[] {
            LandingPage.CONTENT_TYPE_NAME,
        }
    });
    ...
});
...

If you run your project now, your website will display an HTTP 404 error. That’s because you removed the temporary message, and we haven’t defined a home page yet. We will fix that soon. You should still be able to sign in to the administration UI when you navigate to ~/admin.

Create a ViewImports file

The second small step in preparation for displaying content is setting up a ViewImports file.

ViewImports files allow sharing directives across all views in the application or a particular subdirectory. (Typically @using directives and tag helpers.)

Many templates and components will need to use the same resources. Let’s make things easier and use a global _ViewImports file to centrally manage imports for all future templates.

Create a new empty Razor view named _ViewImports.cshtml in the root of your Kickstart.Web project.

Add the following directives and tag helpers:

cshtml
_ViewImports.cshtml

@using CMS.Helpers
@using Kentico.Web.Mvc
@using Kentico.PageBuilder.Web.Mvc
@using Kentico.Content.Web.Mvc.PageBuilder

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Kentico.Content.Web.Mvc
@addTagHelper *, Kentico.Web.Mvc
@addTagHelper *, Kickstart.Web

This will allow any future page template views you add to use common features without explicit @using directives.

See an example _ViewImports.cshtml in our Kickstart repository.

Learn more about the available tag helpers in the Xperience by Kentico.

Now that you have added these configurations to your project let’s move on to the next step: building a page template.

Previous step: Define a page content type — Next step: Build a page template

Completed steps: 6 of 13