Hello World

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, it should be in the Views/Hello folder entitled Index.cshtml:

@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.

Now you can create you first content item with Lynicon.  To do this, start up the site, log in with the admin account from before if you are not already logged in, and navigate to /Lynicon/Items.

Click the '+' button on the bar entitled 'Hello' to see the url template for adding new pages.  Enter 'world' into the url element box and click the 'new page' icon.

This takes you to this page:

Enter the text 'Hello World' as shown into the Message box (a restricted HTML editor).  You will notice the SAVE button goes red.  Click it to save your changes and update the current page view to the left.  You will now see the page shows 'Hello World'.  If you click Log Out and go to /Hello/World you will see it as a public site user does.