This project is read-only.

Displaying Custom ContentPart's

Topics: Core, Writing modules
Mar 12, 2013 at 4:23 PM

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()
    //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();

    //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;

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) 
    //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(
            TemplateName: "Parts/Book"));
Content Handler
public class BookPartHandler : ContentHandler
    public BookPartHandler() {
        //is this correct?
        Filters.Add(new ActivatingFilter<BookPart>("BookType"));
as we do not store the content, the user of the AlterPartDefinition seems to work.
public int Create()
        cfg =>
    return 2;

public int UpdateFrom1()
        cfg =>

    return 2;
Mar 12, 2013 at 11:58 PM
I don't see a question here.
Mar 13, 2013 at 6:40 PM

Sorry about that.

1, In our BookPartDriver, we have specified a view to use "Parts_Book", which it does not pick up. have we done something wrong? (are we missing something?)

2, [SOLVED] Our model when it comes through to a template (we found a name which worked) our model has to be accessed as follows "@Model.Model.Title" which did not seem correct, we expected to use "@Model.Title".
2, Answer - looks like it was due to our driver in the return "Model:part,"

question 1 is still outstanding

Mar 13, 2013 at 10:59 PM
Did you try using shape tracing to see what shape was being used?
Mar 15, 2013 at 6:13 PM
Did you try adding the attachable feature to the part?
Mar 19, 2013 at 5:57 PM
think we have a working solution, the issue seemed to be with the file.

the current workarround is to list the parts directly without any shapes
    <Place Parts_Book="Content"/>
@BertrandLeRoy, yes it was Content-"ContentPart"Type, so Content-BookType.cshtml (we created the file as the Shape tracing tool suggested it, just to get it working)

@jusquiano no need :)