AI OnAI Off
If you copy ContactBlock.cs, make sure to create a unique GUID - to not use the same.
You do not need to create a separate model and a controller, if you do not want to. If you are only displaying data as the editor inputs it, you will probably not need it.
Simple example.
Block type definition (also used as the model):
using System.ComponentModel.DataAnnotations;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using EPiServer.Core;
namespace Alloy.Models.Blocks
{
[SiteContentType(GUID = "176CE440-C869-448B-B2E2-8626D479B368")]
public class MyBlock : BlockData
{
[Display(GroupName = SystemTabNames.Content, Order = 1)]
[CultureSpecific]
public virtual string Message { get; set; }
}
}
Name the view MyBlock.cshtml and place it in /Views/Shared/Blocks
@model Alloy.Models.Blocks.MyBlock
@Html.PropertyFor(x => x.Message)
Check the file /Alloy.Business.Rendering.SiteViewEngine for the definition on where block views are placed.
If you were to create a controller (MyBlockController), and a separate model (MyBlockModel), you could place the view were you initially placed it.
The documentation on the episerver website tells you how to create a page, but doesnt tell you how to create a block with its corresponding model and view.
With Alloy, I have tried copying some of the code to create a new block, but have not had much luck yet.
in Models/Blocks I copied "ContactBlock.cs" to MyBlock.cs and removed its fields and added just one, "name". I am not sure what this is - its kind of like a model. Its not a veiw, and not a controller.
in Models/ViewModels I copied "ContactBlockModel.cs" to MyBlockModel.cs with just one property: name. Presumably this is actually the model. As an aside, I tried creating a property of type long, but this gives errors, it only works for sting.
I copied Views/ContactBlock/index.cshtml to Views/MyBlock/index.thml thus:
I can now Create "My" blocks in the CMS editor, and I can drag them to content areas, but they show as "The "MyBlock" can not be displayed.
How do I get the block to display in the CMS Page Editor?
Once I have figured this out, ill try to get it to display "name" on the actual website.
Basially, I am trying to do a "hello world" block. I cant find any documenation/samples of this other than alloy. Alloy is great, but not easy to reverse engineer without documentation.