Template Variable
Template variables are the mechanism for filtering widgets all at once by the tag or attribute values you select at the top of a Datadog dashboard. They let you switch a single dashboard between environments or services.
Overview
A template variable is a mechanism that is inserted into dashboard queries under a name such as $env, so that when you select a value in the dropdown at the top, the linked widgets all switch at once. It is a concept that matters when you are duplicating dashboards of the same shape for each environment or region, when you want to move quickly to the target service during an incident investigation, and when you want to hand a specific filter to someone as a URL. Autodiscovery and monitor notifications also have mechanisms with the same name, so you also need to confirm first which one is being referred to.
The value selected at the top goes into each widget's query
The dropdowns lined up at the top of a dashboard are template variables. For example, if you select prod in a variable linked to the env tag, all widgets that use that variable are filtered to prod. Besides filtering, you can also switch to using it to group by the selected tag. The values listed as candidates are gathered from the data the widgets read, and for metrics the values that appeared in the last 48 hours are included (as of October 2026; Source: Template Variables). How to interpret it when no values appear as candidates, and where variables sit within dashboards as a whole, are left to the Dashboards explainer.
What you define are three things: the name, what it is linked to, and the range of values
A single variable is determined by three elements. What it is linked to is the key side for tags in KEY:VALUE format, and for logs, APM, and RUM you can also choose attributes such as facets. The name is what it is called when it appears in queries, and by default it takes the name of the linked tag or attribute. The range of values consists of two things: the default value that is applied on load (the default is *) and the values you can select in the dropdown (the default is all of them) (as of October 2026; Source: Template Variables). If you leave the default value as *, right after opening you see the total for all environments. For a screen where you normally look only at production, setting the default value to prod prevents misreading.
- Choose the candidate tag with Add Variable
- Choose the widgets to apply it to
- Decide between filtering and grouping, and decide the default value
Two forms of insertion into queries
The first is insertion as a tag. If you configure each variable for filtering or grouping, then in the widget editor, filtering variables appear as candidates in the from field and grouping variables appear as candidates following the by field, in a form such as $environment. Which role a variable plays is determined by the setting on the variable side, not by the field you put it in. The second is the form that embeds only the value into a string, written as $service.value. You can build a variable into part of a tag value, as in env:staging-$service.value. In log, APM, and RUM widgets you can also use wildcards in the middle of a value (such as *prod*), but following a variable directly with * does not give you a dynamic prefix match (as of October 2026; Source: Template Variables). In text widgets, $env displays the pair of tag and value and $env.key displays the key, so you can show the current filter in a heading.
The combination you selected can be shared through saved views and URLs
When you change a variable's value, parameters beginning with tpl_var_ are added to the dashboard URL. On a screen with $env set to prod, tpl_var_env=prod is added, and if you hand over this URL, the other person can open it with the same filter. Combinations you use repeatedly go into saved views. From the Saved Views menu you can give the current selection a name, save it, and recall it later. Just changing a value is not reflected in a saved view, and the Default view can only be edited by changing each variable's default value (as of October 2026; Source: Template Variables). In an incident response runbook, writing the already-filtered URL rather than the name of the dashboard reduces hesitation for whoever opens it.
Other mechanisms called by the same name
Besides the one in dashboards, Datadog has two other mechanisms called template variables. Template variables in Autodiscovery take a form such as %%host%%, and the Agent fills in values in container configurations (Source: Autodiscovery Template Variables). Monitor notification messages also have built-in variables such as {{value}} and {{threshold}}, and the official documentation calls these Template variables too (as of October 2026; Source: Variables). With dashboard variables, a person selects the value on screen; with the other two, the Agent or the monitor fills in the value automatically. When looking for an answer through search, adding whether it is about dashboards helps you avoid mixing them up.
Keys split into env and environment do not switch with a single variable
If tag keys are split by product, such as env in metrics and environment in logs, a variable linked to env does not apply to logs that only have environment. How to align env / service / version across products is summarized in Unified Service Tagging, and how to attach tags itself is summarized in Tag. What to check next is which widgets on your own dashboards do not change their numbers even when you change the variable's value. If you find one, open the tag keys of the data that widget reads and compare whether the spelling matches the variable's key.