Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

imageImage Removed Image Added

The most basic scenario of content routing would then be implemented like this:

...

Code Block
languagec#
public ActionResult Index(TestContent data)
{
	return View(data);
}

Routing

The standard routing in MVC will send all urls matching the url string (subject to constraints) to the controller.  The DataRoute<T> route will only match urls where a persisted data item of type T corresponding to the url exists.

DataRoute<T> uses convention to map url variables (e.g. {action}) to an address which specifies a particular data item to retrieve.  The address is a tuple composed of all url variable values where the url variable is underscore followed by a number, starting zero.  E.g.

  shops/{_0}/{_1}

could be a url pattern for shops where the town they are in matches {_0} and the name of the shop matches {_1} e.g.

  shops/brighton/berts-fish-and-chips

If there are no url variables e.g. for the home page where the url is the empty string, there is only one (or zero) data item for the route.

Lynicon supports a use pattern where multiple data routes with different types have the same url pattern.  This allows differently typed content items to exist within the same space of urls.

Editing

User management is a core part of Lynicon.  This means that you can always log in to a Lynicon site on the url /lynicon/login.  Once logged in with Editor role, routing behaves differently.  For a url backed by an existing persisted data item, Lynicon will now show you an editor when you navigate to that url.  The default editor is a right hand side panel with the current page displayed to the left.

For a url without a data item, navigating to it shows you a blank editor as before, with an indication that no page exists at this location.  If you fill in data and save it, because there is now a persisted data item for this page, the next time you view it it will be as aboveThis 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.