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

Saving Custom Data

When customizing the CMS there will come a point where you want to save some data that is not content or media and re-use it.

For this you can use GlobalData, which stores a string with an alias.

public class GlobalData
{
    public Guid Id { get; set; } = Guid.NewGuid().NewSequentialGuid();
    public string? Alias { get; set; }
    public string? Data { get; set; }
    public DateTime DateCreated { get; set; } = DateTime.UtcNow;
    public DateTime DateUpdated { get; set; } = DateTime.UtcNow;
}

You can save data into Global Data using the following method, you need to serialise your data into a string

var saveResult = await Mediator.Send(new SaveGlobalDataCommand
{
    GlobalData = new GlobalData
    {
        Alias = "YourAlias",
        Data = "SerialisedData"
    }
});

Once it's saved it's very easy to get the data out by using this extension method

var mydata= await Mediator.GetGlobalData<MyDataType>("YourAlias");

Global data is cached by default and auto flushed whenever SaveGlobalDataCommand is used. However, if you want to bypass the cache and manually call for the data you can use

var globalData = await mediator.Send(new GetGlobalDataCommand
{
    Alias = "YourAlias", 
    Cached = false
});

Did you know, we use Global Data to power the Global Settings in the CMS

PreviousReusing Content EditorsNextUsing AppState Events

Last updated 7 months ago