The basic requirements of content management are to persist arbitrary structured data associated with a group of urls,
allow that data to be edited through a UI, and to provide that data to be inserted into a page template.
This is done in a clean light-touch way in Lynicon by simply extending the Route class. Lynicon provides a generic
DataRoute class, which when used, manages retrieval of an arbitrarily (within certain specifications) typed data item and
provision of it to the controller's action method via model binding.
The most basic scenario of content routing would then be implemented like this:
- Create a content type TestContent
public class TestContent : BaseContent { public string Title { get; set; } }
- Register a DataRoute<TestContent> in RouteConfig.cs, sending requests to TestController action Index
... routes.AddDataRoute<TestContent>("test", "test/{_0}", new { controller = "test", action = "index" }); ...
- Add a parameter on the Index method of type TestContent named (by convention) 'data'.
public ActionResult Index(TestContent data) { return View(data); }
This then operates as follows:
- The AddDataRoute<TContent>() method adds a special DataRoute to the route table.
- This uses the route variable {_0} to index into the repository of TestContent items stored in the Data System, it gets the relevant content data and plugs it into the MVC routing system.
- The routing system then assigns it to the 'data' parameter of the action method (it is always the 'data' parameter by convention).
- The controller then passes the content data into the view to be rendered.
Add Comment