Skip to content

Create strongly typed views and generate DocTypes, DataTypes, MediaTypes and MemberTypes for Umbraco 7 using a code-first approach.

License

Notifications You must be signed in to change notification settings

nicbell/ucreate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UCreate Build status Nuget

Create doc types, media types, data types, member types and member groups for Umbraco 7 using a code-first approach. Inspired by USiteBuilder.

Available on NuGet

PM> Install-Package UCreate

Usage

The only configuration you'll need to get started is an app setting in your web.config. This tells UCreate to sync your doc types, media types, data types, member types and member groups on application start.

...
<appSettings>
    ...
    <add key="UCreateSyncEnabled" value="true" />
    ...
</appSettings>
...

DocType example

Doc types support property inheritance. Here is a list of available icons.

[DocType(Name = "Page With Title",
    Icon = "icon-zip color-blue",
    AllowedAsRoot = true,
    AllowedTemplates = new[] { "PageWithTitle" },
    DefaultTemplate = "PageWithTitle",
    CompositionTypes = new[] { typeof(TaggedPage) })]
public class PageWithTitle : PublishedContentModel
{
    public PageWithTitle(IPublishedContent content) : base(content)
    { }

    [Property(Alias = "heading", TypeName = PropertyTypes.Textstring, Description = "Heading for page", Mandatory = true, TabName = "Content")]
    public string Heading {
        get { return Content.GetPropertyValue<string>("heading"); }
    }

    [Property(Alias = "itemDate", Name = "Item Date", TypeName = PropertyTypes.DatePicker, Description = "Date", Mandatory = true, TabName = "Content")]
    public DateTime ItemDate
    {
        get { return Content.GetPropertyValue<DateTime>("itemDate"); }
    }
}

MediaType example

Media types support property inheritance.

[MediaType(Name = "Folder With Cover",
    Icon = "icon-folder color-blue",
    AllowedAsRoot = true,
    IsContainer = true,
    AllowedChildTypes = new[] { typeof(FolderWithCover), typeof(Image) })]
public class FolderWithCover
{
    [Property(Alias = "coverImage", TypeName = PropertyTypes.MediaPicker, Description = "Cover image.", Mandatory = true)]
    public string CoverImage { get; set; }
}

DataType with prevalues example

[DataType(EditorAlias = Umbraco.Core.Constants.PropertyEditors.ColorPickerAlias,
    Name = "Nice Color Picker",
    Key = "1bfca1e7-95d0-485e-bd94-9fe9c2b8821f",
    DBType = DataTypeDatabaseType.Nvarchar)]
public class NiceColorPicker : IHasPreValues
{
    /// <summary>
    /// Implementing PreValues
    /// </summary>
    public IDictionary<string, PreValue> PreValues
    {
        get
        {
            return new Dictionary<string, PreValue> {
                {"1", new PreValue("ff00ff")},
                {"2", new PreValue("1f00f1")},
                {"3", new PreValue("123123")},
                {"4", new PreValue("ffffff")}
            };
        }
    }
}

MemberType example

[MemberType(Name = "Employee", Description = "Member who represents an employee", Icon = "icon-user color-green")]
public class Employee
{
    [MemberProperty(Alias = "jobTitle", TypeName = PropertyTypes.Textstring, Description = "Employee's job title", Mandatory = true, TabName = "Job Details", CanEdit = true, ShowOnProfile = true)]
    public string JobTitle { get; set; }

    [MemberProperty(Alias = "jobDescription", TypeName = PropertyTypes.Textarea, Description = "Employee's job description", Mandatory = false, TabName = "Job Details", CanEdit = true, ShowOnProfile = false)]
    public string JobDescription { get; set; }

    [MemberProperty(Alias = "profilePicture", TypeName = PropertyTypes.MediaPicker, Description = "Admin profile picture", Mandatory = false, CanEdit = true, ShowOnProfile = true)]
    public string ProfilePicture { get; set; }
}

MemberGroup example

[MemberGroup(Name = "Staff")]
public class Staff
{
}

Strongly typed views

In order to use your doc types on the front-end you need to enable the PublishedContentModel factory. UCreate can do this for you if add the following app setting:

...
<appSettings>
    ...
    <add key="UCreatePublishedModelsEnabled" value="true" />
    ...
</appSettings>
...

Then using the doc types in your views is pretty simple.

@inherits UmbracoTemplatePage<PageWithTitle>

@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>PageWithTitle</title>
</head>
<body>
    <h1>@Model.Content.Heading</h1>
</body>
</html>

Contributing

If you have a fix for something don't be shy, submit a pull request.

About

Create strongly typed views and generate DocTypes, DataTypes, MediaTypes and MemberTypes for Umbraco 7 using a code-first approach.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published