Copied to clipboard

Flag this post as spam?

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


  • Sören Deger 726 posts 2833 karma points c-trib
    May 21, 2014 @ 11:20
    Sören Deger
    0

    How get properties of current node in custom propertie editor?

    Hi,

    I have create my first propertie editor in Umbraco 7 and with this code in my myPropertieEditor.controller.js I get the name and id of current node:

    angular.module("umbraco")
    .controller("SP.myPropertieEditor",

    function ($scope,editorState) {
    $scope.editorState = editorState;
    alert("TEST: " + $scope.editorState.current.name + " - " + $scope.editorState.current.id);

    });

     

    But Idon't know how I get the other custom properties of current node. Have everyone an idea?

     

    Best regards

    Sören

  • Tom 117 posts 443 karma points
    May 21, 2014 @ 12:29
    Tom
    0

    maybe you can use the contentResource http://umbraco.github.io/Belle/#/api/umbraco.resources.contentResource

    contentResource.getById(editorState.id).then(function(node){
    
       node.??? //do stuff with the node???
    
    });
    
  • Sören Deger 726 posts 2833 karma points c-trib
    May 21, 2014 @ 13:12
    Sören Deger
    0

    Hi Tom,

    thank you. With this code I can get the name or id (node.name, node.id). But do you know how I can get the value of a specific propertie of this node?

  • Tom 117 posts 443 karma points
    May 21, 2014 @ 13:32
    Tom
    102

    I think you can do something like this:

     contentResource.getById(editorState.id).then(function(node){
    
       var theTabYouWant = 0;
       var thePropertyYouWant = 3;
       var theValueYouWant = node.tabs[theTabYouWant].properties[thePropertyYouWant].value;
    
    });
    

    But you need to know the structure of the data. But you can use Chromes debugger to visualize the data.

  • Sören Deger 726 posts 2833 karma points c-trib
    May 21, 2014 @ 13:43
    Sören Deger
    0

    Thank you very much for this excellent description ! It works great :-)

    Sören

  • Tom 117 posts 443 karma points
    May 21, 2014 @ 13:44
    Tom
    0

    Glad I could help :) I'm not sure its the best way to do it - but it works!

  • Jeremy Pyne 106 posts 246 karma points MVP c-trib
    Sep 08, 2014 @ 19:47
    Jeremy Pyne
    0

    This is suboptimal as the data can change at the whim of a designer.

  • oscar olsson 6 posts 26 karma points
    Oct 20, 2014 @ 14:56
    oscar olsson
    0

    Yeah if the user change the tab-name the code will break.

    It would be great it there where a method like:

    var x = node.properties[thePropertyYouWant].value;
  • damian vander wilt 12 posts 56 karma points
    Nov 18, 2014 @ 06:03
    damian vander wilt
    0

    But wait (he says so many months later;), there is!

            contentResource.getById($scope.selectedAuthorId) //  [Smoke Signals Authors]
                .then(function (content) { 
                    var xNodeProperties  = contentEditingHelper.getAllProps(content);
                });
    

    from http://umbraco.github.io/Belle/#/api/umbraco.services.contentEditingHelper ::

    contentEditingHelper (service in module umbraco.services ) getAllProps()

    Returns all propertes contained for the content item (since the normal model has properties contained inside of tabs)

  • Luke 110 posts 255 karma points
    May 08, 2015 @ 09:55
    Luke
    0

    Hiya,

    Sorry for joining late but once you have:

    var xNodeProperties  = contentEditingHelper.getAllProps(content);
    

    how do you retrieve the property you want by its alias??

    Regards, L

  • Marcin Zajkowski 104 posts 566 karma points MVP 3x c-trib
    Dec 02, 2015 @ 14:49
    Marcin Zajkowski
    3

    Hello,

    I created simple helper function for handling it. It is using underscore to filter and retrieve proper value for desired property by alias.

    $scope.getPropertyValueByAlias = function (myAlias) {
    
        return _.findWhere(_.filter(editorState.current.tabs, function(tab) {
            return _.some(tab.properties, { alias: myAlias }); 
        })[0].properties, { 
            alias: myAlias // It could be any else property you want
        }).value;
    
    };
    

    Hope that it will be helpful for anyone else.

  • Simon Dingley 1427 posts 3326 karma points c-trib
    Feb 08, 2016 @ 15:36
    Simon Dingley
    0

    Thanks for sharing this it saved me a great headache. I would have thought there would be an easier way to access this data without first having to know the structure.

  • Simon Dingley 1427 posts 3326 karma points c-trib
    Jul 12, 2016 @ 13:13
    Simon Dingley
    0

    Is this still the easiest way to get properties from a node using the property alias?

    Thanks, Simon

Please Sign in or register to post replies

Write your reply to:

Draft