Skip to main content
ZenHub houses documentation to support you if you’re using Contensis Classic. Contensis Classic includes our WYSIWYG and templating features. If you’re working with a newer version of Contensis, Contensis.com is your go-to place to find anything Contensis-related when building with content types.
Logo

Routing

Introduction

This article will show you how to display published news articles on your website using routing from site view.

Site view is a node tree structure that allows you to define published URLs for attached content.

In Contensis, an entry can be attached to a node and the resulting URL will normally be reflective of that node structure. This is similar to working with a folder structure. However, unlike a traditionally-built site containing folders – with content files physically located within individual folders – site view only defines the website structure, the actual content is located in a central database. This means an item of content can easily be associated with multiple nodes in your website structure.

Step 1

Using site view, create a node called News off the root node of the site.

The screenshot shows a node without an attached entry. When entries are added to this node area, the icon will change to display a folder icon.

Further details of icon types and their indications can be found at:

Step 2

Create a content type called News Record and add the following fields:

Field typeNameProperties
Text Title Set as title field
Text Introduction  
Text Article  

Set the required properties, then press Save and Publish to publish the content type.

Note: You can set a default location in the Content type properties panel. This will determine where newly created entries are attached in site view. We will work on the assumption that this is NOT the case for this article.

Step 3

Create one or more entries from the News Record content type. Save and Publish them.

Step 4

Open Site view and add one or more of the entries to the News node.

Step 5

Switch views to display the classic Contensis Project Explorer. If not already present, create a folder called 'App_Code' directly off the site root, e.g. Intranet/App_Code. The folder must exist at this location. You will need to ensure the C# file type is assigned as a content type.

Note: The App_Code folder works a lot like the Bin folder, with the exception that it can be used to store source code rather than compiled code.

Warning: Be aware that changes to your App_Code folder can result in your website becoming unavailable. We strongly recommend testing any changes before committing them to a live environment.

Step 6

Create a new C# file, called 'NodeRoutingConfig' within your AppCode folder. The path will be \App_Code\NodeRoutingConfig.cs. Add the following code:

using Contensis.Website;

[assembly: WebActivatorEx.PostApplicationStartMethod(typeof(RouteHandling.NodeRouteConfig), nameof(RouteHandling.NodeRouteConfig.Setup))]

namespace RouteHandling
{
    public class NodeRouteConfig
    {
        public static void Setup()
        {
            // Default is "/site-elements/renderers"
            //NodeRouteHandling.DefaultRendererPath As String = "/site-elements/whatever"

            // Only enabled if required
            NodeRouteHandling.Enabled = true;

            // Handle specific scenarios when an entry is not assigned or override a specific path
            NodeRouteHandling.HandleRoute(node =>
            {
                switch (node.Path.ToLower())
                {
                    case "/news":
                        return "news-listing";
                }
                return null;
            });
        }
    }
}


Note (1) Node route handling is not enabled by default in your project, so has to be enabled, i.e. set to 'true' as in the code example above.

Note (2) When entries are attached to the path /news, Contensis will automatically determine what content type those entries are created from.

Step 7

We now need to create the rendering mechanism which will allow you to see the rendered results. There are two .aspx files required - a 'web page' and a 'Razor view'. The web page can be created from a page template of your choosing, but needs to have a placeholder to accommodate the addition of the Razor view.

These files should ideally be created in the secure site-elements area of your project folder structure, for example:

/site-elements/renderers

Use meaningful names to identify your files too, as in the examples below:

  • newsRecord.aspx
  • newsRecordRazor.aspx

The Razor view will allow you to programmatically access the entryId, nodeId, and contentTypeId values from the query string using the Contensis Delivery API.

Having created your Razor view, open to edit, and add:

@using Zengenti.Contensis.Delivery;

@{
    var entryId = HttpContext.Current.Request.QueryString["entryId"];
    var client = ContensisClient.Create();

    var entry = client.Entries.Get(entryId);

}

<style>
html {font-family:arial, helvetica,sans-serif; font-size: 1em}

</style>

<h1>@entry.Get("EntryTitle")</h1>

<div><p><strong>@Html.Raw(entry.Get("introduction"))</strong></p></div>

<div><p>@Html.Raw(entry.Get("article"))</p></div>

Change entryId to either nodeId or contentTypeId as required. Save and then Publish.

Note: EntryTitle is the system generated API name for the designated title field. introduction is the API name of the field that contains the introduction, defined in the content type. article is the API name of the field that contains the news content, defined in the content type.

Edit the web page, add the Razor view, then Save and Publish.

Step 8

We now need to check that we can preview a news article.

Click to open a news entry, press Preview and the content will display at the desired location, for example:

https://[domain]/en-gb/news/[article]/