Customise item templates in list controls
Some users of Contensis want to be able to customise what a generic listing control displays. An example of this would be a listing of college courses along with custom metadata of start date and course code. This can be achieved in Contensis with the use of a Razor view.
This article assumes you have already followed our guide to adding metadata.
Limit the listing to only include pages with metadata
Following the same method as above, this time you need to select the metadata you want to limit the pages by.
- Under the column section of the popup window select your metadata. Metadata columns are prefixed with MD_ so will appear near the bottom fo the list.
- Under type select isNotNull.
- Save the filter and then save the listing control.
Create a Razor view to use as your item template
Now you need to create a Razor view to be your listing item template, create a new Razor view and paste in the HTML you would like to use for each list item. You can then make reference to your custom metadata by using:
You can also access all other properties available on a content node. Here is an example of a Razor item template which shows the page title, a link to the page, it's description and the custom metadata for course code and start date.
<h2><a href="@CurrentNode.Path">@CurrentNode.Title</a></h2><p>@CurrentNode.Data.Description</p><p>Course Code: @CurrentNode.Data.CourseCode</p><p>Start Date: @CurrentNode.Data.CourseCode</p>
For a full list of properties available on a content node you can check out our WebAPI reference
Attach the Razor view to the listing control
Now you have your Razor template you just need to attach it to the listing control.
- Edit the page containing your listing control and edit the listing.
- Under the Layout section, press Browse and select the Razor view you just created. Press Save, then press Save on the listing control window. This will attach the Razor view to your template. Save the page and then preview to ensure the steps were all applied.
In addition to customising the listing item template you may want to filter down the content displayed by the listing control, this is done using data filters and is covered in Setting up data filters on list controls.
Was this article helpful?