EPiServer 7 example properties

Welcome EPiServer

This is my first post about EPiServer 7. For those who are not familiar, its a CMS and we are using it at Making Waves. If you are not using it at work, this and other posts about this technology probably won’t help you much.

I want to share my views about writing properties according to KISS principle.

After adding new „Page Type” (using Visual-Studio-Extension-in-EPiServer-7), we get commented out example property, which looks like this:

[ContentType(DisplayName = "DefaultPage1", GUID = "bbcc0cb1-d3f4-46fa-95e4-fb87218405f3", Description = "")]
public class DefaultPage1 : PageData
{
    /*
            [CultureSpecific]
            [Editable(true)]
            [Display(
                Name = "Main body",
                Description = "The main body will be shown in the main content area of the page, using the XHTML-editor you can insert for example text, images and tables.",
                GroupName = SystemTabNames.Content,
                Order = 1)]
            public virtual XhtmlString MainBody { get; set; }
        */
}

Write less code if you can

It gives much too much than I normally need. These are 3 default properties that I start most pages with:

[ContentType(GUID = "3873922c-258f-4dd4-a169-7ba2f1e2d3ca")]
public class MyPage : PageData
{
    [CultureSpecific]
    [Display(
        Order = 1)]
    public virtual String Heading { get; set; }

    [CultureSpecific]
    [Display(
        Order = 2)]
    [UIHint(UIHint.Textarea)]
    public virtual String MainIntro { get; set; }

    [CultureSpecific]
    [Display(
        Order = 3)]
    public virtual XhtmlString MainBody { get; set; }
}

My thoughts:

  • [Editable(true)] – its editable by default no need to repeat yourself.
  • GroupName = SystemTabNames.Content, – most pages have properties that fits only to this default TabName, don’t repeat yourself…
  • [UIHint(UIHint.Textarea)] – looks like TestArea when editing by Editor
  • No Name and Description – you can define it once (and make it localizable out of the box), look in Alloy Template for Resources\LanguageFiles\PropertyNames.xml (and _ReadMe.txt). They are removed from Page Type definition from the same reason.

What do you think about this setup?

Order

Try not to give your next property sequent numbers like „Order = 4”. Sooner or later you will have to add a property somewhere in the middle and reenumerate halt of properties. Its better to start your next group of properties with 10, 20 and so on. In Alloy they are using 200, 210, 300, 305, but I would not go into so big numbers.


[CultureSpecific]
[Display(
    Order = 1)]
public virtual String Heading { get; set; }

[CultureSpecific]
[Display(
    Order = 2)]
[UIHint(UIHint.Textarea)]
public virtual String MainIntro { get; set; }

[CultureSpecific]
[Display(
    Order = 3)]
public virtual XhtmlString MainBody { get; set; }

[Display(
    Name = "Start date",
    Order = 10)]
public virtual DateTime StartDate { get; set; }

[Display(
    Name = "Finish date",
    Order = 11)]
public virtual DateTime FinishDate { get; set; }

[CultureSpecific]
[Display(
    Name = "Event name",
    Order = 12)]
public virtual string EventName { get; set; }

Note that I put Name = „Event name” here in the code and not in resources like I suggested earlier. This are properties that will probably show up only once through your application and maybe it is better to manage names from here.

References

Alloy Templates

The one big reference is Alloy Templates which is great and big base of good code and examples. I think everybody should browse through this code before developing EPi7 solutions and come back often for new inspirations and tricks.

Update

I try not to use property Heading. I am trying to bind the heading to the PageName. There is always PageName on each page and it can be edited in the markup through (MVC Razor):

@Html.PropertyFor(m => m.PageName)
Advertisements
Ten wpis został opublikowany w kategorii EpiServer i oznaczony tagami , , , , . Dodaj zakładkę do bezpośredniego odnośnika.

3 odpowiedzi na „EPiServer 7 example properties

  1. Petter Klang pisze:

    Good stuff!
    One thing I would add if your looking for simplicity and your always adding the three properties Heading, MainIntro and MainBody. Why not create a block or basepage with them on and then either add the block or inherent from the basepage. This would reduce your definitions to only be in one place.

    • Good point. I was regarding both ways of doing this, and here my conclusions:

      Why not basepage? – „http://en.wikipedia.org/wiki/Composition_over_inheritance” (maybe not exact relevant, but I am not a big fun of “over-inheritance”). I consulted this approach with colleague working in project where they used inheritance and I didn’t work well through time for them.
      Why not block then? Every page have different styling and structure so it cannot use block. Editing on page gives better Editor experience that editing on block.

      Another case is that some pages needs only Heading and MainIntro, and other only Heading and MainBody, so you will loose flexibility.

      I totally agree that it is good to have it in one place, but here I think it has too many drawbacks.

  2. Pingback: Resharper templates for Block and PageData | Show me the code

Możliwość komentowania jest wyłączona.