Copied to clipboard

Flag this post as spam?

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


  • Alex Skrypnyk 5772 posts 21986 karma points MVP 4x admin c-trib
    Aug 09, 2020 @ 19:19
    Alex Skrypnyk
    0

    How to get section alias in Angular

    Hello Community

    I'm working on a custom dashboard and I need to know section alias in the angular code, how can I do it?

    How to get section alias specified in package.manifest?

    Thanks, Alex

  • Anders Bjerner 443 posts 2545 karma points MVP 4x admin c-trib
    Aug 09, 2020 @ 19:53
    Anders Bjerner
    1

    Hi Alex,

    There is an Angular service called $routeParams. I don't think Umbraco has any documentation on it as the service comes from Angular, and not Umbraco.

    Anyways, you can inject the service into your controller via DI like this:

    angular.module("umbraco").controller("MyController", function ($scope, $routeParams) {
    
        console.log($routeParams);
    
    });
    

    For my simple section, the controller will then write the following object to the log:

    {
        section: "data",
        url: "dashboard.aspx?app=data"
    }
    

    I'm not sure how relevant url is, but section gets you the alias of your section 😉

  • Alex Skrypnyk 5772 posts 21986 karma points MVP 4x admin c-trib
    Aug 09, 2020 @ 21:28
    Alex Skrypnyk
    0

    Hi Anders,

    Thank you very much for your answer!!!

    But, it doesn't work for 100%, so I'm getting Umbraco section alias, but I wanted to get a section alias inside custom dashboard, I specified dashboard and sections in package.manifest

    "dashboards": [
        {
          "alias": "pictureOfTheDay",
          "view": "~/App_Plugins/CustomDashboards/PictureOfTheDay/pictureoftheday.html",
          "sections": [ "content" ],
          "weight": -10
        }
      ],
    

    This section alias - "alias": "pictureOfTheDay",

    Thank you very much!!! Alex

  • Anders Bjerner 443 posts 2545 karma points MVP 4x admin c-trib
    Aug 09, 2020 @ 22:10
    Anders Bjerner
    100

    Oki then. If I'm understanding you correctly, you're then actually looking for the alias of the dashboard and not the alias of the section? Is this correct?

    When the overall dashboard of a section is rendered in the backoffice, it consists of one or more tabs, and each tab may consist of one or more properties.

    In most cases, you custom dashboard will result in a tab that then has a single property with your custom dashboard view. I'm not even entirely sure how you can have multiple properties under a single tab, but the UI seems to support that.

    To get the alias of your custom dashboard, try playing around with these:

    // Gets the overall dashboard object (this is not your dashboard)
    console.log($scope.dashboard);
    
    // Gets the alias of the tab
    console.log($scope.tab.alias);
    
    // Gets the alias of the property
    console.log($scope.property.alias);
    

    In most cases, the two aliases are going to be the same.

  • Alex Skrypnyk 5772 posts 21986 karma points MVP 4x admin c-trib
    Aug 10, 2020 @ 22:36
    Alex Skrypnyk
    0

    This is exactly what I was looking for, thank you so much, Anders!!!!

Please Sign in or register to post replies

Write your reply to:

Draft