Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Laurence Gillian 600 posts 1219 karma points
    Dec 01, 2016 @ 17:08
    Laurence Gillian
    0

    Document Type Composites

    Hey!

    Wondering how Ditto handles composite Document Types?

    For the example below, would you create 2 pocos?

    Article

    • Attributes on Document Type
      • Include Meta

    Meta

    • Meta (tab) [900]
      • metaTitle: Title (Textstring)
      • metaDescription: Description (Textstring)
      • socialTitle: Social Title (Textstring)
      • socialDescription: Social Description (Textstring)
      • socialImage: Social Image (Media Picker)

    Something like:

    namespace Undiscovered.Site.Logic.Model.Content
    {
        using Composite;
        public class Home
        {
            public string Header { get; set; }
            public Meta Meta { get; set; }
        }
    }
    

    and...

    using Our.Umbraco.Ditto;
    
    namespace Undiscovered.Site.Logic.Model.Content.Composite
    {
        public class Meta
        {
            [UmbracoProperty("metaTitle", null, false, "Default Value, wahoo!")]
            public string Title { get; set; }
            public string Description { get; set; }
            public string SocialTitle { get; set; }
            public string SocialDescription { get; set; }
            public string SocialImage { get; set; }
        }
    }
    

    Which does not work ;-)

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Dec 01, 2016 @ 17:16
    Lee Kelleher
    101

    Hi Lau,

    Ditto is working directly with the IPublishedContent object, which doesn't care about the doctype compositions (in the nicest possible way) ... it has a bunch of properties - which is what Ditto will pull values from.

    In your case, if you are mapping your current content node to the Home type, it will loop over the properties, find Meta and look for a property on the node called "Meta" - which it doesn't look like it has ... so leaves it as null.

    Because you'll want to re-apply your content node to the nested class... then you can add a processor attribute called CurrentContentAs to the Meta property...

    [CurrentContentAs]
    public Meta Meta { get; set; }
    

    Then that should work as you'd expect it to.

    Hope this helps?

    Cheers,
    - Lee

  • Laurence Gillian 600 posts 1219 karma points
    Dec 01, 2016 @ 17:20
    Laurence Gillian
    0

    Cheers Lee! I knew I had read about it somewhere in the docs ;-) Thanks again! Laurence

Please Sign in or register to post replies

Write your reply to:

Draft