How to add conditional text to a Zendesk macro
By Jake Marsh · Updated
To make one Zendesk macro write different text for different cases, install Slotwell, add a pick list such as [[choice:Resolution|Refund|Replacement]] to the macro, and wrap each case in [[#if Resolution = Refund]] ... [[#elseif ...]] ... [[else]] ... [[/if]]. When an agent picks an answer in the Slotwell sidebar, only the matching branch goes into the reply, and blanks in the other branches are hidden and never required.
Steps
- Edit the macro in Admin Center > Workspaces > Agent tools > Macros.
- Add the question that drives the branches, usually a
choiceblank. Addquietif the answer should steer the text without being printed:[[choice:Resolution|Refund|Replacement|Store credit; quiet]]. - Write the branches with block tokens, each on its own line.
- Save, then run Check macros in Slotwell. It flags blocks that never close or close twice, and conditions on a label no blank has or on a value that isn't an option.
- Try it. Try a macro shows the exact reply and ticket changes for any answer.
Example
[[choice:Resolution|Refund|Replacement|Store credit; quiet]]
[[#if Resolution = Refund]]
We refunded $[[number:Refund amount; min=1]].
[[tag:refund_issued]]
[[#elseif Resolution = Replacement]]
A replacement ships on [[date:Ship date; default=+2 business days]].
[[else]]
We added store credit to your account.
[[/if]]
An agent who picks Replacement sees only the Ship date field. The reply contains one sentence, and the refund_issued tag is added only when Refund was picked. A line that holds only a block token disappears from the reply, so no stray blank lines are left.
Conditions you can write
| Condition | True when |
|---|---|
Resolution = Refund | The answer is Refund |
Resolution != Refund | The answer is anything else |
Items contains Wheels | A text or multi answer includes Wheels |
Notes is empty / Notes is not empty | The blank was or wasn't answered |
Notes (a bare label) | The blank was answered |
Join conditions with and and or, for example [[#if Plan = Premium and Region = EU]].
Set tags and fields per branch
| Token | What it does, only in the branch that applies |
|---|---|
[[tag:refund_issued]] | Adds a tag to the ticket |
[[field:360001234567=refund]] | Sets a ticket field. Drop-downs by option name or tag, checkboxes with true or false |
These run alongside the macro's own actions, which apply as usual when the agent clicks Fill reply. Check macros reports field ids that don't exist or are inactive and drop-down values that aren't options.
Why one macro instead of several
A refund, a replacement and store credit usually share the greeting, the order details and the sign-off. Keeping them in one macro means editing that shared text once. Agents pick one macro and answer one question instead of choosing between near-identical names.
What it costs
Slotwell is priced per Zendesk account by number of shared macros, billed monthly by Zendesk: Team $99 a month (up to 25), Professional $199 (up to 250), Enterprise $349 (any number). Every feature, including conditional text, is on every plan, with a 14-day free trial. See the Slotwell documentation for every token.
Slotwell
Fill-in macro prompts: macros that ask agents for details, check answers and add conditional text. From $99 a month per Zendesk account.
Questions
Can I nest one condition inside another?
Yes. A block can sit inside another branch, as long as each [[#if ...]] has its own [[/if]]. Check macros reports any block that never closes or closes twice.
Are blanks inside a skipped branch still required?
No. Blanks in a branch that doesn't apply are hidden from the form and never required.
Can a branch depend on the requester or organization?
Branches depend on answers. Give a blank a default= from a requester or organization field and add quiet, and the condition follows that value unless the agent changes it.
Do the branch tokens show up if the macro is applied from Zendesk's own menu?
The sidebar shows Your reply has N blanks to fill, and Fill the blanks opens the form so the branches resolve. Square-bracket tokens are safest for that route.
More Slotwell guides
More Zendesk guides
- How to set up 301 redirects in a Zendesk help center (Sprucewell)
- How to pause or cancel a Recharge subscription from Zendesk (Skipwell)
- How to show BambooHR employee info in Zendesk (Staffwell)
- How to cancel or hold a Magento order from a Zendesk ticket (Satchelwell for Magento and Adobe Commerce)