Content Types

Content types in Weavy are classes of content items. You can also see them as “templates” for content items. When you add a custom content type, Weavy will automatically create user interface elements for adding and editing instances of your content type.

Content class

To add a new content type to Weavy you should create a class extending Weavy.Core.Models.ItemBase. In the example below we are creating a content type for meeting minutes.

using System;
using System.ComponentModel.DataAnnotations;
using System.Runtime.InteropServices;
using System.Web.Mvc;
using Weavy.Core.Models;

namespace Wvy.Models {

    [Serializable]
    [Guid("D16FE490-AB4D-4D42-B9F4-D93E6F297940")]
    [Content(Icon = "clipboard-text", Name = "Meeting note", Description = "Keep your notes organized with this meeting minutes template.", Parents = new Type[] { typeof(FilesApp), typeof(Folder) })]    
    public class MeetingMinutes : ItemBase {

        public string Location { get; set; }

        [Display(Name = "Date", Description = "Date and time of the meeting")]
        public DateTime? Date { get; set; }

        public string Attendees { get; set; }
        
        [AllowHtml]
        [Required]
        [DataType(DataType.Html)]
        [Display(Name = "Note text")]
        public string Body { get; set; }
    }
}

Class attributes

As shown above, all content types in Weavy must be decorated with the [Serializable] and [Guid] attributes.

Make sure to give your class a unique Guid, otherwise it will not be recognized by Weavy.

To further customize your content type you can also decorate it with the [Content] attribute. This attribute has the following properties:

  • Icon - name of an icon to use when displaying the content item.
  • Color - color to use for the icon.
  • Name - display name for the content item, e.g. “Meeting note”.
  • Description - a description to use for the content item.
  • SingularName - determines how a singular item will be referred to, e.g. “a meeting note”.
  • PluralName - determines how multiple items will be referred to, e.g. “meeting notes”.
  • Children - a list of allowed child content types
  • Parents - a list of allowed parent apps and/or content types
  • CreateMode - determines if content items of the content type should be created in a modal window or a new page
  • EditMode - determines if content items of the content type should be edited in a modal window or a new page

Fields

Content fields are pieces of information that can be added to a content type. Content fields have a name and a type and are specific to a content type. There can be several of each field type on any given content type.

In the example above, we have added 4 fields that make sense for meeting minutes; a text field representing the meeting location, a date field representing the date and time of the meeting, a text field for writing down the names of the people attending the meeting, and finally a text field for the meeting notes.

For a property on a content type to be considered a content field, it must be declared as public read-write, i.e. the property has the public access modifier and have both a get and a set accessor.

Content fields must also have one of the following supported types:

  • enum
  • byte
  • short
  • int
  • long
  • bool
  • double
  • float
  • string
  • Guid
  • DateTime
  • TimeSpan

Nullables and Lists of the above types are also supported, e.g. int?, List<string> and List<DateTime?>.

Field attributes

By decorating your fields with one, or more, of the following attributes you can customize how the field is displayed, edited and/or validated.

Datatype

By default, Weavy will look at the property type (in this case string) when deciding which editor to use for the field. By decorating a field with the [DataType] attribute you can specify an additional type to associate with the field. This value will then be used by the UI to determine which editor to use for the field.

[AllowHtml]
[DataType(DataType.Html)]
public string Body { get; set; }

Here we specify that the Body field should be treated as HTML instead of a plain text string. Note that you should always specify [AllowHtml] on Html fields, otherwise ASP.NET MVC will throw an exception saying that “A potentially dangerous Request.Form value was detected from the client…” when you try to create an instance of your content type from the UI.

Display

The [Display] attribute lets you specify a name and description to use for the field.

[Display(Name = "Date", Description = "Date and time of the meeting")]
public DateTime? Date { get; set; }

Validation

By adding one, or more, [Validation] attributes to your fields you can control they are validated.

[Required]
public string Body { get; set; }

Here we specify that the Body property is required and that it must be a valid and fully qualified url.

To control validation even more you can also let your class implement IValidatableObject and add your own custom validation logic.

Views

Weavy has built-in generic view files for rendering any content type, but by adding custom View files (.cshtml) you can customize the rendering of your content type. Custom view files must follow a specific naming convention and be placed in the Views\Content folder. To fully customize the view files for a content type you can add all of the below Views and partial Views.

  • Item-{Name}-{Guid}.cshtml - View that is rendered when an instance of your content type is displayed
  • Edit-{Name}-{Guid}.cshtml - View that is rendered when an instance of your content type is edited
  • _Row-{Name}-{Guid}.cshtml - Partial view that is rendered when an instance of your content type is displayed in a table (in the Files app)
  • _ListItem-{Name}-{Guid}.cshtml - Partial view that is rendered when an instance of your content type is displayed in a list (for instance in search results etc)

Your custom view files must use the naming conventions specified above where you replace {Name} with the name of your content type and {Guid} with the Guid of your content type. So if we wanted to add custom views for the MeetingMinutes content type we should add the following views:

  • Item-MeetingMinutes-D16FE490-AB4D-4D42-B9F4-D93E6F297940.cshtml
  • Edit-MeetingMinutes}-D16FE490-AB4D-4D42-B9F4-D93E6F297940.cshtml
  • _Row-MeetingMinutes-D16FE490-AB4D-4D42-B9F4-D93E6F297940.cshtml
  • _ListItem-MeetingMinutes-D16FE490-AB4D-4D42-B9F4-D93E6F297940}.cshtml