Displaying Custom ContentPart's

Topics: Core, Writing modules
Mar 12, 2013 at 3:23 PM
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;
}
Coordinator
Mar 12, 2013 at 10:58 PM
I don't see a question here.
Mar 13, 2013 at 5:40 PM
Hi,

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

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

the current workarround is to list the parts directly without any shapes
<Placement>
    <Place Parts_Book="Content"/>
</Placement>
@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 :)