Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

Here's how to create a hello world page with Lynicon.

First create this class in HelloContent.cs in the Models folder:

public class HelloContent : PageContent
{
	public MinHtml Message { get; set; }

	public HelloContent()
	{
		BaseContent.InitialiseProperties(this);
	}
}

This model class holds the data for the content which will be shown on the page.  It inherits from PageContent to provide it with standard HTML page metadata fields and to indicate it is being used to provide the content for a whole web page. The MinHtml class is used to store HTML markup, and the editor for this class allows minimal markup. Content classes when constructed should not have null values for reference types because in some contexts the editor to use is determine from the type of the reference stored in a property rather than the declared type of the property.

Now create a controller to use this model:

public ActionResult Index(HelloContent data)
{
	return View(data);
}

Very straightforward! The name of the parameter has to be 'data' by convention. Lynicon will fetch the appropriate content item and provide it to the controller through this variable.

Now create a basic view:

@model LyniconTest2015.Models.HelloContent
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div>
        @Model.Message
    </div>
</body>
</html>

Notice the Message property since it is typed as MinHtml does not require Html.Raw to be used

The last piece is to add a route:

using Lynicon.Routing;
...
routes.AddDataRoute<HelloContent>("hello", "hello/{_0}", new { controller = "Hello", action = "Index" });

Notice you will need to add 'using Lynicon.Routing' to access the extension method 'AddDataRoute'. This special route is where the CMS magic happens. You supply it with the content type and a url template which by convention uses '{_0}', '{_1}', '{_2}' etc to indicate parts of the url that are used to index into the set of content items of the specified type.

 

  • No labels