Last active
August 9, 2016 16:29
-
-
Save csdear/3b1aab0431d03a635b8fdace553d07ed to your computer and use it in GitHub Desktop.
N2 : Page Template : Attributes Cheat Sheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Example with Code Explations | |
https://gist.github.com/davecowart/b1f448dbc7b32f1e624b#file-contentpage-cs | |
ContentPage.cs | |
Attribute|Property…Attribute|Property…Attribute|Property… | |
*/ | |
//1. The N2>>Model>> Page Template | |
using System.Collections.Generic; | |
using Cadence.Web.Helpers.Attributes; | |
using Cadence.Web.Helpers.Extensions; | |
using Cadence.Web.Models.N2.Base; | |
using Cadence.Web.Models.N2.Parts; | |
using N2; | |
using N2.Details; | |
using N2.Installation; | |
using N2.Integrity; | |
using N2.Persistence.Search; | |
using N2.Persistence.Serialization; | |
using N2.Web.UI; | |
namespace Cadence.Web.Models.N2.PageTemplates { | |
//This attribute tells N2 that this is a Page Template, with the user-facing friendly name "Content Page" | |
[PageDefinition("Content Page"] | |
//This attribute tells N2 that this page can only be a child of the listed page types | |
//when the user creates a new page using this template. | |
[RestrictParents(typeof(HomePage), typeof(DepartmentPage), typeof(ContentPage))] | |
//When the user is editing a page created from this template, the admin area displays a tab for Social Media content | |
//the editor controls for the boolean values below will be displayed inside this tab because of their attributes | |
/// Tab areas, I assume for better admin UI/UX. | |
[TabContainer(Containers.SocialMedia, "Social Media", 20)] | |
//Note that the class inherits from AbstractPage - this is a custom type that inherits from an N2 type (N2Item) | |
//but adds some extra functionality. It's recommended to use the AbstractPage (and other related classes) from | |
//existing projects - would be a good idea to create an internal NuGet package that contains these | |
public class ContentPage : AbstractPage { | |
//Rich Text Editor : When the user is editing a page based on this template, this attribute tells N2 that that the user should see a rich text editor, | |
//and it should be displayed inside the Main content tab | |
/// Use for large paragraph sections, body text | |
[EditableFreeTextArea("Content", 5, FreeTextAreaSettingsSet.Simple, ContainerName = Containers.MainContent)] | |
//VERY IMPORTANT VIRTUAL - All editable properties should have the virtual keyword, otherwise N2 will just ignore them. virtual = editable | |
public virtual string Content { get; set; } | |
// CHECKBOX : The attribute on these properties will tell the admin page to render checkboxes inside the SocialMedia tab that was defined in the class-level attribute | |
///param 1 label beside the editable text box . the string property is the label text for the admin editor | |
///param 2 the integer property is the sort index used when displaying the editor inputs in the admin | |
///param 3 the tab containter you are referencing. Here we reference Containers.SocialMedia tab we created. | |
[EditableCheckBox("Show Facebook Button", 200, ContainerName = Containers.SocialMedia)] | |
public virtual bool ShowFacebookButton { get; set; } | |
[EditableCheckBox("Show Twitter Button", 201, ContainerName = Containers.SocialMedia)] | |
public virtual bool ShowTwitterButton { get; set; } | |
[EditableCheckBox("Show LinkedIn Button", 202, ContainerName = Containers.SocialMedia)] | |
public virtual bool ShowLinkedInButton { get; set; } | |
[EditableCheckBox("Show GooglePlus Button", 203, ContainerName = Containers.SocialMedia)] | |
public virtual bool ShowGooglePlusButton { get; set; } | |
} | |
} | |
//2. The Associatted controller setup. e.g., ContentController.cs | |
using System; | |
using System.Linq; | |
using System.Web.Mvc; | |
using AutoMapper; | |
using Cadence.Web.Models.N2.PageTemplates; | |
using Cadence.Web.Models.ViewModels.Content; | |
using N2; | |
using N2.Definitions; | |
using N2.Web; | |
using N2.Web.Mvc; | |
namespace Cadence.Web.Controllers { | |
//tells N2 which type to work with | |
[Controls(typeof(ContentPage))] | |
//make sure to inherit from the ContentController<T> base class | |
public class ContentController : ContentController<ContentPage> { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment