Copied to clipboard

Flag this post as spam?

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


  • Brian Juul Andersen 44 posts 98 karma points c-trib
    Aug 18, 2015 @ 13:34
    Brian Juul Andersen
    1

    MNTP XPath expression for startnode

    Hey there :)

    I got a datatype of type multinode treepicker (MNTP) that I want to use in a macro to pick a node with. I managed to get it to show up in the list of different editors for the macro.

    I use "$current" as an Xpath expression to set the start node for it so it can be used everywhere on the site.

    However .. it only seems to work when used in a doctype and not in a macro (setting start node to current)

    Any ideas on where to begin debugging ?

  • Lars-Erik Aabech 350 posts 1102 karma points MVP 8x c-trib
    Aug 19, 2015 @ 06:46
    Lars-Erik Aabech
    0

    AFAIK, the macro dialog doesn't get any info about your content context.
    That basically means it can't be done. :/ Sorry.

    It could very well be made, though. So you might get lucky if you post a feature request on http://issues.umbraco.org.

  • Brian Juul Andersen 44 posts 98 karma points c-trib
    Aug 19, 2015 @ 10:16
    Brian Juul Andersen
    0

    Thanks for your reply Lars-Erik :)

    Hmm .. I´ll have to think of some other way to solve this.

  • Lars-Erik Aabech 350 posts 1102 karma points MVP 8x c-trib
    Aug 19, 2015 @ 10:20
    Lars-Erik Aabech
    0

    You could always clone the Umbraco source and copy the MNTP property editor (and possibly dialog) and make your own macro parameter. ;)

    https://github.com/umbraco/Umbraco-CMS

  • Brian Juul Andersen 44 posts 98 karma points c-trib
    Aug 31, 2015 @ 08:50
    Brian Juul Andersen
    100

    Thanks for your help Lars-Erik :)

    I got it to work .. sort of.

    I´ll post what I did as others in a similiar situation might benefit from it.

    What I wanted to do was to read the XPath query set on the data type in my controller.

    enter image description here

    I couldn´t find any way to access it from the controller so I ended up with setting the query in the defaultConfig object.

        //the default pre-values
    var defaultConfig = {
        multiPicker: "0",
        showEditButton: false,
        minNumber: 1,
        maxNumber: -1,
        startNode: {
            query: "$site",
            type: "content",
            id: -1
        }
    };
    

    From what I can tell it can be set just like on the datatype.

    Only disadvantage I can see is... if there are changes to the XPath they can not be set from the Umbraco interface but they have to be edited through an editor (ie. Visual Studio)

  • Lars-Erik Aabech 350 posts 1102 karma points MVP 8x c-trib
    Aug 31, 2015 @ 09:07
    Lars-Erik Aabech
    0

    Glad you got it working. :)

    Here's how you make stuff configurable per data type:

    https://github.com/umbraco/UmbracoDocs/blob/master/Tutorials/Creating-a-Property-Editor/part-2.md

  • Brian Juul Andersen 44 posts 98 karma points c-trib
    Sep 01, 2015 @ 06:48
    Brian Juul Andersen
    0

    It seems I spoke too soon :)

    Having tested it a bug showed up ... it didn´t work when the root node had unpublished content which is an old topic I guess ( http://issues.umbraco.org/issue/U4-3443 ). If so .. the start node would resolve to the content tree for all the sites. In other words: when a customer had unpublished content they would be able to peek into other customers sites running on the server. Ofcourse this would happen sooner or later so it was not a stable solution.

    What I did was to write some Angular that would resemble a $site XPath Query. Not an elegant solution but at least it works :)

    Now the defaultConfig object looks like this:

        //the default pre-values
    var defaultConfig = {
        multiPicker: "0",
        showEditButton: false,
        minNumber: 1,
        maxNumber: -1,
        startNode: {
            query: "",
            type: "content",
            id: -1
        }
    };
    

    ... and the block that resolves the XPath query now looks like this:

        //if we have a query for the startnode, we will use that. 
    if ($scope.model.config.startNode.query) {
        var rootId = $routeParams.id;
        entityResource.getByQuery($scope.model.config.startNode.query, rootId, "Document").then(function (ent) {
            dialogOptions.startNodeId = ent.id;
        });
    } else {
        //dialogOptions.startNodeId = $scope.model.config.startNode.id;
        entityResource.getPath($routeParams.id, "Document")
            .then(function (pathArray) {
                dialogOptions.startNodeId = pathArray[1];
            });
    }
    

    I have modified the else section. As it is now it emulates a "$site" query. More logic has to be programmed if you want to emulate other queries.

Please Sign in or register to post replies

Write your reply to:

Draft