t.getContext()

On This Page

    Synchronously get the current context for t. This can be useful if you need the ID of a model that is in scope, or want to check user permissions.

    1 2 3 4 5 6 7 window.TrelloPowerUp.initialize({ 'card-buttons': function (t, opts) { var context = t.getContext(); console.log(JSON.stringify(context, null, 2)); return []; }, });

    And the response would look like:

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 { // id of the current board "board": "59287bae175fb20142c4c282", // id of the current card (if there is one) "card": "59287bec175fb20142c4c363", // capability command, (if there is one) "command": "card-buttons", // id of the current member, "notLoggedIn" if no member is logged in "member": "591f23d52a2eaa0c33e6c187", // id of the Workspace the board is in (if its in one) "organization": "538627f73cbb44d1bfbb58f0", // id of the enterprise the board is in (if its in one) "enterprise": "5cedada40a30f27bdb6e26b7", // read or write permissions for current member per modelType "permissions": { "board": "write", "organization": "write", "card": "write" }, // the current color theme the member is using, e.g. null | "light" | "dark". // it can be null right after the Power-Up is initialized, but will be // updated as soon as the theme finishes loading. Complementing its // usage with t.subscribeToThemeChanges() is highly encouraged. "theme": null, // the locale of the browser, generally a standard 2 character ISO code // see https://datatracker.ietf.org/doc/html/rfc5646#section-2.1 "locale": "en-US", // The color theme used to initialize the Power-Up. "initialTheme": "dark" }

    Troubleshooting

    If t.getContext() is returning undefined in your Power-Up code, ensure you are calling t.signUrl() on your URLs. This ensures your Power-Up iframe HTML pages can communicate with Trello.

    For example:

    1
    2
    TrelloPowerUp.initialize({
      'card-back-section': function (t, options) {
        return {
          title: 'Card Back Section',
          icon: MY_ICON,
          content: {
            type: 'iframe',
            url: t.signUrl('./card-back-section.html'), // call t.signUrl
          },
        };
      },
    });
    

    Now, you should be able to call t.getContext() without issues.

    1
    2
    // inside card-back-section.js
    const t = window.TrelloPowerUp.iframe();
    
    t.render(() => {
      console.log(t.getContext());
    });
    

    Rate this page: