Developer 101 - Shared Content

Introduction to Shared Content

Shared Content allows us to define lists or single items of data or information that do not fit into the model of pages and modules, but yet still need to be actively maintained by content editors. This could be a list of products, blog posts, or news articles, or even just a single item representing a header Partial View that is shared across multiple pages. These items can be global as ‘Shared Content’ items, or attached to a specific module as ‘New Content’.

In many ways, these content items or lists are similar in concept to modules: we create a definition for each one and then create instances of it in order to add actual data items. Modules are added to pages and have a specific output template (or 'code' to execute) whereas Shared Content exist outside the context of pages and have no output template.

You can see the existing content definitions of our Sample Site by navigating to Settings > Content Definitions in Agility. You’ll see that most of the items in the table have a type of “Content List”, which makes perfect sense for list of products, categories, or featured items -  where you’d expect there to be more than one item. You’ll also notice that there’s an item called “Global Header” which has a type of “Content Item” – in practice this also makes perfect sense as the website only has one header, we’re using a content item here so that we can share it across every page on the website and only need to update its properties in one central place.

We don’t need to go into exactly how lists and items are defined here, because they are constructed in exactly the same way as module definitions – you have the same property types available to you and the same input form customization options. The only addition to content lists is that you can specify what properties are displayed on the grid, and what order the items appear in.

Linked Content Properties

Modules and Content Definitions can reference other Content Definitions and their Shared Content instances. This allows for shortcuts to other content, selecting a specific item from that linked list to use in its own context, and flexible content architecture.

Typically, the way you interact with your Linked Content is by selecting or sorting items from it through a variety of Rendered Controls such as a Drop Down List, Checkbox List, or a Grid. Selecting or sorting items will allow you to save the values of the Content IDs that represent each item. Using these saved ID(s) you can filter your Linked Content in C# using the Agility.Web API.

A Linked Content property within a Content Definition or Module Definition has its own set of settings:

  • Content Definition: This is the list of Content Definitions in your Agility instance
  • Content View:
    • User Selectable: This allows the content editor to select an item or list in Digital Content that shares this same Content Definition.
    • Shared Content: This allows the developer to specify exactly which item or list in Digital Content that should be used.
    • New Content: This creates a new instance of the item or list whenever an instance of this Module or Content Definition is saved.
  • Render as:
    • Grid: Renders an embedded view of the selected content items
    • Link: Renders a link that will open a new dialogue displaying the details of this content item or items
    • Dropdown List: Renders a dropdown list of the selected content item or content items
    • Checkbox List: Renders a checkbox list of selected content item or content items
    • Search List Box: Renders a search box list that allows the content editor to search the selected content list and select one or many

When you are coding your Module, you can get a reference to the Linked Content property by Name.

For example, if the Name of your Linked Content property “Products” then you can get a reference to it in C# by using module. Products just like another other module property. Your Linked Content property uses the class IAgilityContentRepository<T> where T is the type of property (Content Definition) from your C# strongly typed API downloaded from Agility. For example, our module.Products would be IAgilityContentRepository<Product>.

Within the IAgilityContentRepostory class, we can filter the List or Item via the following calls:

//filter products by a particular category
    int categoryID = 20; //ContentID of the category
    string categoryRowFilter = string.Format("ProductCategoryID = {0}", categoryID);
    string sortByTitle = "Title ASC";
    IList productsFilteredByCategory = module.Products.Items(categoryRowFilter, sortByTitle);

//get a subset of products from the list
    int skip = 10; //number of products to skip
    int take = 10; //number of products to take
    string rowFilter = ""; //not filtering by anything
    IList products = module.Products.Items(rowFilter, sortByTitle, take, skip);

//get products by their exact Content IDs
    int contentID = 2343;
    string contentIDs = "1232,43543,234";

    //GetById and GetItemsByIDs is found in Agility.Web.Extentions
    Product productByID = module.Products.GetById(contentID);
    IList productsByIDs = module.Products.GetItemsByIDs(contentIDs);

//sort products by IDs
    string sortIDs = "23,19,20,22,21";
    IList productsSortedByIDs = module.Products.SortByIDs(sortIDs);

Note: the syntax for filter follows the standard C# dataview row filter syntax documented here.

Getting Content without Linked Content Properties

There may be cases where your Module doesn’t have a linked content property, but you still want to be able get your “Products”. Or maybe you are getting a Shared Content Item like a Global Header and want to use that to output content in your layout. You can still get reference to their IAgilityContentRepository programmatically assuming you know their Content Reference Name.

IAgilityContentRepository productsRepo = new AgilityContentRepository("Products");

In this example “Products” is the Content Reference Name of the Shared Content List. Once you have the IAgilityContentRepository reference, you can then use the standard .Items(), .Item(), GetById(), GetItemsByIDs(), and SortByIDs() calls to filter or sort your content.

0 out of 0 found this helpful


  • Do you have a list of the various accepted inputs for the "rowFilter" and "sort" parameters when getting items from an AgilityContentRepository?

    There is no where in the CMS where these values could be cross referenced.

    Comment actions Permalink
  • The filter syntax uses the C# dataview row filter syntax which is documented quite nicely I will add this to our docs here.

    For "sort" it simply takes this format:

    Comment actions Permalink

Please sign in to leave a comment.