ZauberCMS
  • 🪄Welcome to ZauberCMS
  • Getting Started
    • 💡Quick Start
      • Databases
  • Creating A Website
    • 📹Website Build Video Tutorial
    • Content Types
      • Element Types
      • Compositions
    • Current Content Properties
      • Textbox & Textarea
      • Text Editor (Radzen)
      • Text Editor (TinyMCE)
      • Numeric
      • True / False
      • Rating
      • Checkbox, Dropdown & Radio Lists
      • Media Picker
      • Navigation
      • Material Icon Picker
      • Content Picker
      • Date Picker
      • Custom Component Picker
      • Api Key Picker
      • Colour Picker
      • Block List Editor
      • Editor Notes
      • Google Map Location Picker
      • Simple List Manager
      • Simple Dictionary Manager
      • SEO Property
      • Code Editor
      • Colour Theme Picker
    • Content
      • Publish & Unpublish
    • Querying Data
      • Extension Methods
    • Views
    • Controllers (Route Hi-Jacking)
    • Custom Components
    • Users & Roles
      • Restrict Access By Role
    • Logs
    • Audit
    • Global Settings
      • Using Global Settings
    • SEO Sitemaps
    • Hosting
  • Extending ZauberCMS
    • Overview
    • BlockListEditor
      • Content Block Preview
      • Content Block
    • Custom List Data
    • Custom Content Property
    • Custom Validation
    • Custom Admin Sections
      • Section Nav Group Menu
      • Trees
        • Tree Context Menus
      • Reusing Content Editors
    • Saving Custom Data
    • Using AppState Events
    • Before & After Save
    • Email & Storage Providers
    • Seed Data
    • SEO Checks
  • Identity
    • Overview
    • External Authentication Providers
    • Account Layout
  • Language
    • Overview
    • Adding Language Dictionaries
    • Setting The Language
    • Using Language Dictionaries
  • AppSettings
    • Detailed Errors
    • Media Settings
    • Enable Path Urls
Powered by GitBook
On this page
  1. Extending ZauberCMS

Custom List Data

There are three List Content Properties (DropdownList, RadioButtonList & CheckboxList). These either take a manual key/value that the user can put in, or you can define your own IDataListSource which really opens up these editors.

public interface IDataListSource
{
    /// <summary>
    /// Name of the data list source
    /// </summary>
    string Name { get; }

    /// <summary>
    /// Description of the data list source.
    /// </summary>
    string Description { get; }

    /// <summary>
    /// Represents the Icon property of a data list source.
    /// </summary>
    string Icon { get; }

    /// <summary>
    /// The full name of the implemented data source class including namespace.
    /// </summary>
    string FullName { get; }

    /// <summary>
    /// Retrieves a list of items from a data source.
    /// </summary>
    /// <param name="scope">The service scope used for dependency injection.</param>
    /// <param name="currentContent">The current content object.</param>
    /// <returns>A collection of DataListItem objects.</returns>
    IEnumerable<DataListItem> GetItems(IServiceScope scope, Models.Content? currentContent);
}

As you can see the GetItems returns a list of DataListItem which is a simple class which is esentially a key/value

public class DataListItem
{
    public string Name { get; set; } = string.Empty;
    public string Value { get; set; } = string.Empty;
}

As long as you can convert your data source into this format, there is really no limit to the sort of things you could make a data source. The example below show how to get a list of the available content views (This is actually used within the site on the content editor).

public class ContentViewsDataSource(ExtensionManager extensionManager) 
: IDataListSource
{
    public string Name => "Content Views";
    public string Description => "List of the available content views";
    public string Icon => "tag";
    public string FullName => GetType().FullName ?? string.Empty;

    public IEnumerable<DataListItem> GetItems(IServiceScope scope, Content? currentContent)
    {
        var allContentViews = extensionManager.GetInstances<IContentView>(true);
        return allContentViews.Values.Select(x =>
        {
            var type = x.GetType();
            return new DataListItem
            {
                // Get the name of the component
                Name = type.Name,
                // Get the full name of the component
                Value = type.FullName!
            };
        })
        .OrderBy(x => x.Name)
        .ToList();
    }
}
PreviousContent BlockNextCustom Content Property

Last updated 10 months ago