Copied to clipboard

Flag this post as spam?

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


  • Jay 425 posts 652 karma points
    Sep 27, 2016 @ 08:37
    Jay
    0

    Ditto + Nested Content

    Hi All,

    Was wondering if anyone tried Ditto + Nested Content before and if there's any code example with Custom Controllers for the Nested Content and also the Nested Nested Content mapping and rendering?

    Thanks

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 27, 2016 @ 08:47
    Lee Kelleher
    1

    Hi JLon,

    Yep it works fine. Nested Content returns a collection of IPublishedContent items, which then can be passed to Ditto for mapping.

    (This was done by design, as Matt & I developed both packages)

    A code example would be...

    var items = model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("ncAlias");
    var myModel = items.As<MyViewModel>();
    

    Then myModel would contain be an IEnumerable<MyViewModel>.

    If you have a view-model for your page, then you can skip this manual step and let Ditto handle it, like so...

    public class MyPageModel
    {
        [UmbracoProperty("ncAlias")]
        public IEnumerable<MyViewModel> Items { get; set; }
    }
    

    then in your controller, you would only map the content node...

    var myModel = model.Content.As<MyPageModel>();
    

    I hope this makes sense?

    Cheers,
    - Lee

  • Jay 425 posts 652 karma points
    Sep 27, 2016 @ 08:53
    Jay
    0

    Thanks Lee,

    Will check it out tonight. Starting out with Ditto to trying to figure things out

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 27, 2016 @ 08:57
    Lee Kelleher
    3

    Insider tip... Matt "dittoified" the Faneo starter kit at CodeCabin16, here's the zip link: https://dl.dropboxusercontent.com/u/138129/Host/DittoDemo.zip

  • Jay 425 posts 652 karma points
    Sep 27, 2016 @ 10:42
    Jay
    0

    :D thanks Lee. Massive help

  • Jay 425 posts 652 karma points
    Sep 27, 2016 @ 11:46
    Jay
    0

    Hey Lee,

    I've noticed that you use DittoView which implement from the UmbracoViewPage.

    Is there any extra functionality that can be done when you use the DittoView instead of the UmbracoViewPage?

    Thanks

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 27, 2016 @ 13:25
    Lee Kelleher
    0

    The DittoView directive is a new feature in Ditto v0.10, (it came from an idea that Matt developed called DitFlo). The idea behind it is that you no longer need to explicitly call Ditto's .As<T> extension method from any controller code.

    So if you have...

    @inherits DittoView<MyPageModel>
    

    then Ditto would handle the mapping of the current page's content node. (Previously you would have had to call Model.Content.As<MyPageModel>() somewhere - either in a controller or view code-block)

    Then to access your view-model, you can use... @Model.View and if you still need access to the current page's content node, it is still accessible via @Model.Content.

    I hope this helps?

    Cheers,
    - Lee

  • Jay 425 posts 652 karma points
    Sep 27, 2016 @ 13:55
    Jay
    0

    ic. Even lesser codes then. Nice.

    How will your controller looks like? I had a check in the UmbTextPageController which still comes with the .As<> so it confuses me.

    Thanks Lee

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 27, 2016 @ 14:01
    Lee Kelleher
    0

    Previously, if all your controller was doing was calling Ditto's .As<T> method, then you no longer need that controller.

    If it was doing other code, then you can still use it. The DittoView directive will check if the model passed in to the view matches the target type. If it doesn't then it attempts to convert it. If it's an IPublishedContent, then Ditto knows what to do with it and maps all the properties.

    There's a lot going on with it, and it should handle most scenarios... but if you're curious about what it's doing exactly, the source-code is here:
    https://github.com/leekelleher/umbraco-ditto/blob/develop/src/Our.Umbraco.Ditto/Web/Mvc/DittoView.cs#L27

    Cheers,
    - Lee

  • Jay 425 posts 652 karma points
    Sep 27, 2016 @ 16:19
    Jay
    0

    Nice one Lee, always helpful. I'll check it out tonight once i got home. Thanks for all the help.

  • Jay 425 posts 652 karma points
    Sep 28, 2016 @ 07:28
    Jay
    0

    Hey Lee,

    Everything seems to be working nicely.

    I've got a quick question on the processor. The DittoProcessorAttribute seems straightforward. What I wasn't so sure is the DittoMultiProcessorAttribute.

    How does it works? I had a check in the TitleAttribute.cs and it comes with the below

    public class TitleAttribute : DittoMultiProcessorAttribute
        {
            public string TitleAttr { get; set; }
    
            public TitleAttribute()
                : base(Enumerable.Empty<DittoProcessorAttribute>())
            {
                base.Attributes.AddRange(new[] {
                    new UmbracoPropertyAttribute(TitleAttr),
                    new AltUmbracoPropertyAttribute("Name")
                });
            }
        }
    

    The bits that confuses me is the
    base.Attributes.AddRange(new[] { new UmbracoPropertyAttribute(TitleAttr), new AltUmbracoPropertyAttribute("Name") });

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 28, 2016 @ 08:45
    Lee Kelleher
    0

    The DittoMultiProcessor is used to group multiple processors together. It's more for if you're adding the same processor attributes to your POCOs properties again and again, then you can group them.

    The base.Attributes.AddRange bit is how they are added.

    Does that make sense, or need more explanation?

    Cheers,
    - Lee

  • Jay 425 posts 652 karma points
    Sep 28, 2016 @ 10:37
    Jay
    0

    I'm a bit confuse on the TitleAtr being passed in.

    the bits like in the below, how do Ditto know that the Umbraco Property Alias is actually called "Title" but the parameter which has been passed in is TitleAtr

    Does the DittoMultiProcessorAttribute works that it looks for the Title, if it doesn't exist then it looks for the Alternative which will be Name

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 28, 2016 @ 12:22
    Lee Kelleher
    1

    To be honest, I'm not familiar with the TitleAttribute code - Matt dev'd it for his demo. (I haven't looked at it in any great detail) I think it was to show an example of how DittoMultiProcessor could be used.

    The processors that are defined within a DittoMultiProcessor implementation, are like a pipeline, they'll run sequentially - passing the value of one processor to the next one.

    In the case of TitleAttribute, the TitleAttr property would be passed in like so...

    [Title(TitleAttr = "yourTitleAlias")]
    public string MyTitle { get; set; }
    

    then it can work with the alias. But if you don't pass an alias in, then Ditto will assume the alias is the same as your POCO property name.

    Cheers,
    - Lee

  • Jay 425 posts 652 karma points
    Sep 28, 2016 @ 12:51
    Jay
    0

    ic. much clearer now. That's how you pass parameter in.

    Thanks Lee

  • Jay 425 posts 652 karma points
    Sep 29, 2016 @ 07:12
    Jay
    0

    You made my day Lee. The package is awesome. It works so well with Nested Content (and also Nested Nested Content). Amazing work :)

    I've got a bit of a question on the Lazy Loading and also the Ditto Cache.

    How/ When do you use the Lazy Loading and the DittoCache attribute?

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 29, 2016 @ 09:06
    Lee Kelleher
    0

    I don't use the Lazy Loading feature much myself. It's there for when you want to delay Ditto mapping the property value until its runtime.

    An example would be that you have a news section with hundreds of child nodes, this might be an expensive task mapping in advance, so you can lazy load them for when they are needed.

    To use this, make your property as virtual...

    public virtual IEnumerable<MyModel> NewsItems
    

    then Ditto will do some dark-magic around it and make the property as a Lazy<IEnumerable<MyModel>>.

    In the next version of Ditto (v0.11 under development), you'll also need to add a processor to the property called [DittoLazy], (there's a long discussion about it on our GitHub repo, issue #191).


    The DittoCache is another performance feature... if you have a custom processor that is doing an expensive thing - e.g. database query or HTTP request. Then you can cache the result.


    I know we need to clear up the documentation on these things. Our roadmap is to make v0.11 stable, work on the docs and release as a v1.0.

    Just to note, we're always open to contributions, especially around any dev notes or documentation.

    Cheers,
    - Lee

  • Jay 425 posts 652 karma points
    Sep 29, 2016 @ 09:27
    Jay
    0

    Ic. Nice one Lee.

    Do the DittoCache hooked into the Umbraco event to clear it out? As in on Publish, Save, Delete, etc?

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 29, 2016 @ 09:40
    Lee Kelleher
    0

    No, it doesn't automatically clear the cache for you.

    You can set the CacheDuration (in seconds)... or you can figure out the cache key and expire it manually. Here's the code that builds up the cache key.

    Cheers,
    - Lee

  • Jay 425 posts 652 karma points
    Sep 29, 2016 @ 09:58
    Jay
    0

    Ic. Thanks Lee

  • Jay 425 posts 652 karma points
    Oct 07, 2016 @ 15:51
    Jay
    0

    Hey Lee,

    Quick question,

    When i'm within a Surface Controller, I've got the below which render the partial view.

    I've got @inherits DittoView

    I've just noticed in the Surface controller there's a squiggle on the model and it's showing the below when i hover over. Any idea what's that? Or should i just ignore it?

    Thanks

    enter image description here

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Oct 07, 2016 @ 15:55
    Lee Kelleher
    0

    Hey JLon,

    Not sure, I haven't seen that warning squiggle before, but I've also not seen entering the full path of the partial-view file before either. Interesting how the intellisense knows about the model-type of the partial-view.

    I don't have any resolution to offer, so ignoring it is my only advice :-(

    Cheers,
    - Lee

  • Jay 425 posts 652 karma points
    Oct 07, 2016 @ 16:35
    Jay
    0

    Okie dokie. Thanks Lee.

    Just found out, it might have been my Resharper freaking out there I guess

Please Sign in or register to post replies

Write your reply to:

Draft