Access bound Figma variable names in Template API

Open
#390 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
figma, typescript

Research direction

Start by reading the Template API entry points for getString(), getBoolean(), getEnum(), and getInstanceSwap(), then trace how visual properties such as fills and strokes are exposed from a Figma instance. Check existing Template API tests and identify how they verify property access. Done means templates can read a bound variable name for the requested property and the behavior is covered by tests.

Written by the indexing model from the issue text.

Description

feature request

Problem

The Template API provides getString(), getBoolean(), getEnum(), getInstanceSwap() — but has no way to read bound Figma variables on visual properties (fills, strokes, text color).

When a component's fill color is set via a Figma variable (e.g. errorColor), the template cannot access that variable name to generate the correct code token.

Use Case

We have a Flutter Badge component where background color is controlled by bound Figma variables. The variable can be any color from our full design system palette — primaryColor, errorColor, successColor, warningColor, and many others. In code, these map directly to theme accessors:

PbBadge(
  value: 'Text',
  color: context.theme.primaryColor,
)

PbBadge(
  value: 'Error',
  color: context.theme.errorColor,
)

Currently the template cannot output color: at all — developers must manually look up the correct token.

Proposed API

instance.getBoundVariable('fills')    // → "primaryColor"
instance.getBoundVariable('strokes')  // → "borderColor"

Template usage (Flutter example):

const fillVar = instance.getBoundVariable('fills');
const colorPart = fillVar ? `\n  color: context.theme.${fillVar},` : "";

export default {
  example: figma.code`PbBadge(
  value: "${value}",${colorPart}
)`,
};

This would generate:

PbBadge(
  value: 'TextValue',
  color: context.theme.primaryColor,
)
Dominant language
TypeScript
Stars
1.6k
Forks
126
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from figma/code-connect

All issues in figma/code-connect

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.