Hello
Full code example - the code has //TODO comments where we are unsure.
We are having some difficulty in showing our custom content part. It does not use the Template we are expecting and we cannot access the Part in the view (most likely we are missing a step)
Thank you in advance.
Controller Action
Tried 2 ways, based of the Blog module
public ActionResult List()
{
//TODO:
//Way 1 - trying to get the following to work
//IEnumerable<dynamic> books = _catalogueService.Get(3).Select(b => _services.ContentManager.BuildDisplay(b, "Summary"));
//var list = Shape.List();
//list.AddRange(books);
//dynamic viewModel = Shape.ViewModel()
// .ContentItems(list);
//return View((object)viewModel);
//Way 2 - Tried this as well
var book = _catalogueService.Get(3).Select(b => _services.ContentManager.BuildDisplay(b, "Summary")).FirstOrDefault();
return new ShapeResult(this, book);
}
Creating the contentitems
Similar to my previous post here, we are loading our content item from WCF using the content manager as follows
IEnumerable<Book> books = GetFakeData(); //mimics the service call
foreach (var book in books)
{
var bp = _services.ContentManager.New<BookPart>("BookType");
bp.Title = book.Title;
bp.Isbn = book.Isbn;
results.Add(bp);
}
return results;
Driver Display method
The template is named, however it uses the view call "Content-BookType.cshtml"
protected override DriverResult Display(BookPart part, string displayType, dynamic shapeHelper)
{
//TODO:
//cannot get this to use the Parts/Book.cshtml template
//tried with the model: and with out
//tried with the Templatename: and without
//?
return ContentShape("Parts_Book",
() => shapeHelper.Parts_Book(
Model:part,
TemplateName: "Parts/Book"));
}
Content Handler
public class BookPartHandler : ContentHandler
{
public BookPartHandler() {
//TODO:
//is this correct?
Filters.Add(new ActivatingFilter<BookPart>("BookType"));
}
}
migrations
as we do not store the content, the user of the AlterPartDefinition seems to work.
public int Create()
{
ContentDefinitionManager.AlterPartDefinition("BookPart",
cfg =>
cfg
.WithField("Isbn")
.WithField("Title")
);
return 2;
}
public int UpdateFrom1()
{
ContentDefinitionManager.AlterTypeDefinition("BookType",
cfg =>
cfg.WithPart("BookPart"));
return 2;
}
|