Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1282 posts 2739 karma points
    Jun 18, 2015 @ 19:51
    Amir Khan
    0

    MNTP how to check what's picked from other nodes?

    Hi,

    I am struggling a bit conceptually with the best way to do this:

    I have a list of content pages in a shared repository, I want some of these content pages to be related to content in other parts of the site. I'm using a multi-node tree picker in the shared content nodes to pick which other nodes they are related to.

    How would I go about rendering the content of the shared node on the nodes that were picked?

    I can't do it the normal way where I'd just put a MNTP on the node and render the picked content.

    Thanks for any insight as to how to make this happen best!

    Amir

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 18, 2015 @ 20:52
    Jeavon Leopold
    100

    Hi Amir,

    I think maybe something like the below (1234 is the node id of the shared node) and assuming that the nodes you want are all children of the shared node?

    @{
        var relatedItems = Umbraco
                           .Content(1234)
                           .Children
                           .Where("mntpPropertyAlias.CsvContains(@0)",CurrentPage.Id.ToString());
    
        foreach (var item in relatedItems)
        {
            <div class="3u">
                <section class="is-feature">
                    <a href="@item.Url" class="image image-full">
            <img src="http://placehold.it/350x150" alt="" />
             </a>
                    <h3><a href="@item.Url">@item.Name</a></h3>
                </section>
            </div>
        }
    }
    

    Jeavon

  • Ed Knight 16 posts 99 karma points
    Jun 23, 2015 @ 19:56
    Ed Knight
    0

    Hi Amir,

    Have you thought about using Relations?

    Step one would be to first create the Relation Type in the Dev section. The best bet here would be to use Bi-Directional.

    After that I would recommend checking out the nuPickers Package as all those pickers can have a Relation Alias tied directly to them. Once you have the dataType created with the Relation Tied to it, you could use it to replace your MNTP.

    Whenever you Save and Publish a node with the picker it will update the relations with the Parent / Child Ids. Now that you have that relation data you can use the Relations API service to query based on the RelationAlias and pull out those that are related to the current node.

    Ed

  • Amir Khan 1282 posts 2739 karma points
    Jun 23, 2015 @ 19:59
    Amir Khan
    0

    Hi Ed,

    I've not, what's the advantage of using relations? How does it support a relation with multiple nodes?

    Jeavon's solution for MNTP worked so marking as answer, but curious as to why you think relations might be a better option.

    I'm trying to relate a post to one or several locations and MNTP seems to work nice since it brings up the search for list view, now can have multiple start nodes, etc.

    Thanks!

    Amir

  • Ed Knight 16 posts 99 karma points
    Jun 23, 2015 @ 20:22
    Ed Knight
    1

    Hi Amir,

    Yes totally - Jeavon's solution met what you were looking for and the multiple start node sounds like a plus for the Out of the Box MNTP.

    Using relations can provide a few deeper hooks and more info in the back office in some instances. For example. Say you have Blog Post A and it is selected on 10 nodes in your content tree, using relations you could programmatically see all those selections. Better still in nuPickers there is a "RelatedLabels" datatype that will display to you all the related nodes to the content Node you are on. So your editors could look at Post A in the back office and there is a list right there showing all the pages that have it selected. (you can even hook in a macro to customize that list display)

    Displaying relations to the front-end there is the Relation API. We have used it and really like it, but just keep in mind that using it is potentially one more query to the DB.

    The original post that got me into using Relations was "Who Picked This". It's a little dated now because it refers to Ucomponents on earlier Umbraco versions, but the concepts and usefulness are still the same and transferable to to an implementation using the nuPickers.

  • Amir Khan 1282 posts 2739 karma points
    Jun 24, 2015 @ 20:56
    Amir Khan
    0

    Ed, that is def interesting. Do you know if you could unselect the related content from the associated node? That would be huge.

    -Amir

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Jun 25, 2015 @ 08:46
    Hendy Racher
    0

    Hi Amir,

    Yes that's possible by using the Relations Only save format. (Note: this works in v1.4.1 - there's currently an issue in v1.5.0+ but this will be fixed for the next release)

Please Sign in or register to post replies

Write your reply to:

Draft