Variables from Frontmatter

Setting Variables in Frontmatter

Variables can be defined in YAML frontmatter at the top of your document.
---
company:
  name: Acme Corp
  industry: Manufacturing
  employees: 121
category: Home
---

Using Variables from Frontmatter

Inline in text

# {% $company.name %} Dashboard

{% $company.name %} has {% $company.employees %} employees.

Pass directly to attributes

{% big_value
  data="demo_daily_orders"
  title=$company.name 
  value="sum(total_sales)"
/%}

Template into strings

{% line_chart
  data="demo_daily_orders"
  title="Revenue for {{ $company.name }}" 
  x="date"
  y="sum(total_sales)"
/%}

Template into SQL

```sql home_sales
select * from demo_daily_orders
where category = '{{ $category }}'
```

Variables from Input Components

Some components create variables that can be used elsewhere in your markdown, for example the dropdown component, and other input components.

Setting Variables in Input Components

When you add an input component, it creates a variable using the id attribute.
{% dropdown
  id="category_dropdown" 
  data="demo_daily_orders"
  value_column="category"
/%}
All available filters for your page can be found in the Filters tab in the sidebar. Each filter component offers different filter properties. For example, the dropdown component offers a .selected property, a .literal property, and a .filter property.

Using Variables from Input Components

Pass to attributes

Note, not all attributes can accept variables from input components.
{% table
  data="demo_daily_orders"
  filters=["category_dropdown"] 
%}

Template into SQL

```sql category_analysis
select * from demo_daily_orders 
where category = {{ category_dropdown.selected }} 
```

Fallback Values

Add fallback values using pipes |.
```sql category_analysis
select * from demo_daily_orders 
where category = {{ category_dropdown.selected | 'Electronics' }} 
```

Conditional Blocks

Conditional blocks [[...]] will only be included if all variables within it resolve to non-empty values.
```sql category_analysis
select * from demo_order_details
where transaction_amount > 500 
[[ and category = {{ category_dropdown.selected }} ]] 
```

Data Types

Variables can be:
  • Strings: name: John Doe
  • Numbers: age: 30
  • Booleans: active: true
  • Arrays: colors: [red, green, blue]
  • Objects: company: { name: Acme, industry: Manufacturing }

Nested Access

Use dot notation to access nested properties, and square brackets to access array indices:
{% $company.name %}       # Acme
{% $targets.revenue %}    # 1000000
{% $colors[0] %}          # red