Copied to clipboard

Flag this post as spam?

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


  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 22, 2017 @ 13:11
    Chriztian Steinmeier
    0

    Render items from MNTP with ModelsBuilder

    Hi all,

    I have a simple page with an MNTP for selecting a number of items to show (the items are all the same Doctype).

    I would like to use a separate partial for rendering the items and ideally I'd like to use ModelsBuilder syntax inside the partial (so Model.Content.EmailAddress instead of Model.Content.GetProperty("emailAddress") but if that's not possible, I guess I'll have to live with it :-)

    What's the ideal way to do this?

    Just getting the items from the MNTP looks like it's way more work than it ought to be??

    I'm using Umbraco v7.5.11 at the moment...

    /Chriztian

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Mar 22, 2017 @ 13:49
    Dave Woestenborghs
    100

    Hi Chriztian,

    Do I read this correctly...are you doing razor ?

    But joking aside.

    If you install this package : https://our.umbraco.org/projects/developer-tools/umbraco-core-property-value-converters/

    And rebuild your models all your MNTP Picker properties will return an IEnumerable<IPublishedContent>

    So you can do something like this in Razor :

    @foreach(var item in Model.PickerProperty) 
    {
    <p>@item.EmailAddress</p>
    }
    

    Dave

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 22, 2017 @ 14:04
    Chriztian Steinmeier
    0

    Thanks Dave,

    Yes, I'm actually spending waaaay too much time in Razor - not my happiest place to be honest :-)

    I kind of figured it out - I can actually just "declare" my partial:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Person>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    

    Which let me use ModelsBuilder syntax inside the partial.

    So in the View currently doing the Split() thing, e.g.:

    var people = Model.Content.People.Split(',');
    @foreach (var personId in people) {
        var person = Umbraco.TypedContent(personId);
        @Html.Partial("Person", person)
    }
    

    This works, but it's ugly :)

    Using the PropertyValue Converters could pretty this up, I guess - they will be built-in from v7.6.0 or so, right?

    Thanks again for chipping in,

    /Chriztian

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Mar 22, 2017 @ 14:12
    Dave Woestenborghs
    0

    Hi Chriztian,

    Yes, I'm actually spending waaaay too much time in Razor - not my happiest place to be honest :-)

    I understand. Had to fix a xslt macro on a old v4 site a while ago...felt like meeting an old girl friend and you don't remember her name.

    Using the PropertyValue Converters could pretty this up, I guess - they will be built-in from v7.6.0 or so, right?

    Yes. I read somewhere that it will be part of the core. Just don't remember if it's 7.6 or 7.7

  • Janae Cram 63 posts 439 karma points MVP 8x c-trib
    Mar 22, 2017 @ 15:46
    Janae Cram
    1

    I believe it's in 7.6 (according to the feature list) ;) https://our.umbraco.org/contribute/releases/760

Please Sign in or register to post replies

Write your reply to:

Draft