Coder Social home page Coder Social logo

episerver-extended-categories's Introduction

Extended Categories

This is an extenstion to the Episerver CMS that allows the use of managed pages as categories. This is intended to replace/deprecate the existing Episerver category system.

To Use

#1. Create the Category Page

Create a page type to represent a category (called CategoryPage in the examples below). This is no different than any other Episerver page. Model and template it however you like.

Once the type is created, create a structure of categories in the page tree.

#2. Add the Category Assignment Property

Add the following property to the page types you want to categorize -- so, to ArticlePage in the default Alloy install, for example.

[AllowedTypes(new Type[] { typeof(CategoryPage) })]
[IndexAsCategories]
public virtual IEnumerable<ContentReference> Categories { get; set; }

By default, this will render as a content area-style draggable interface. You can browse for CategoryPage content to add, or just drag them in from the tree.

Note that this is content page-centric. So, when viewing a content page (an ArticlePage to continue our example), you link it to categories (CategoryPage objects) by dragging them in from the tree. It does not work the other way around -- you do not edit a category and assign content to it.

#3. Display Assigned Content for Categories

<ul>
foreach(var page in CategoryManager.GetContent(Model.CurrentPage.ContentLink))
{
	<li>@Html.PageLink(page)</li>
}
</ul>

Alternately, there's an extension method on PageData:

<ul>
foreach(var page in Model.CurrentPage.GetAssignedContent())
{
	<li>@Html.PageLink(page)</li>
}
</ul>

GetContent returns an IEnumerable<PageData> of all the pages assigned to the category referenced by the passed-in ContentReference.

Technical Details

The only necessary modification is to index the reverse relationship between content and categories. Remember, the content page has an IEnumerable<ContentReference> representing the categories, so it already knows about the relationship. We only need to find a way to discover the reverse, from the category side. A category needs to find all the pages on which it has been assigned.

An OnContentPublished event indexes this relationship. This index is then queryed by the GetContent method to produce the assigned pages.

CategoryRepostory is injected for ICategoryRepository by default. CategoryRepository uses the built-inDynamic Data Store (DDS) to store the reverse relationship. (Episever Find users will likely want to re-implement to use Find as the index.)

In the event changes require a re-index, a scheduled job called "Reindex Category Assignments" will delete all assignments and re-index the entire repository. Execution time obviously depends on the volume of content and number of assignments.

episerver-extended-categories's People

Stargazers

Vincent avatar Bob Davidson avatar Henrik Nystrom avatar

Watchers

James Stout avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.