IContentTemplate
The IContentTemplate interface allows you to create a "content template", i.e a predefined component config in code, which will then be presented to the user on the "Saved templates" tab in the "Add Content" dialog. A content template implementation has a name and a description, and a JsonData property which returns the component config as JSON. The JSON is a essentially a ContentMeta class, just like the IContentResolver implementations use.
Interface declaration
public interface IContentTemplate { string Name { get; } string Description { get; } string JsonData { get; } }
Example
In this example, we defined a content template called "Styled submit button" which is basically the "Submit button" component which is part of the "Lisa.Modules.FormComponents" module, but with certain properties pre-populated, the cssclass property will be set to "form-control-submit-button disabled" and the "caption" property will be set to "Submit".
If the user goes to the "Saved templates" tab in the "Add Content" dialog and clicks this template, the Submit button component will be inserted with these two properties prepopulated with the specified values.
public class StyledSubmitButton : IContentTemplate { public string Name => "Styled submit button"; public string Description => "A standard Submit button which has predefined settings for the caption and the CSS class attribute."; public string JsonData => JsonConvert.SerializeObject(GetContentMeta()); private ContentMeta GetContentMeta() { return new ContentMeta() { ComponentId = new Guid("79ae0d9a-3efd-4b68-b759-4f8d38b97139"), Properties = new Dictionary<string, object>() { { "cssclass", "form-control-submit-button disabled" }, { "caption", "Submit" }, }, Areas = null, PreviewMarkup = null }; } }
Registration
This is how the implementation is registered into the DI container in Veva, this should be done in your module config file (The class which implements IModule).
public void ConfigureServices(IServiceCollection services, IConfiguration configuration) { services.AddTransient<IContentTemplate, StyledSubmitButton>(); }