Loading...
Loading...
Use this skill to use Liquid variables in LookML for dynamic SQL, HTML, and Links, including advanced patterns for query optimization.
npx skill4agent add lkrdev/lookml_skills lookml-liquid{{ value }}{% if condition %}valuerendered_value_filters['view.field']parameter_name._parameter_value| sql_quote_filtersTRUEFALSE| sql_boolean_in_query_is_selected{{ view.field._in_query | sql_boolean }}_in_queryrequired_fields{{ field._value }}linkGROUP BYrow['view.field']_in_query_is_selected| Variable | Definition | Critical Difference (Totals) |
|---|---|---|
| Returns | Remains |
| Returns | Returns |
[!WARNING] If you useto conditionally render logic for a dimension, that logic will fail (return false) in the Totals row. Use_is_selectedif you need the logic to persist in totals, or explicitly handle the_in_querystate for totals if that is the desired behavior.false
actiondefault_valuedescriptionfiltershtmllabelview_labelgroup_labelgroup_item_labellinksqlsql_onsql_table_name| Variable | Definition | Usage |
|---|---|---|
| The raw value of the field. | A, H, LI |
| The formatted value of the field. | A, H, LI |
| The value formatted for URL filtering. | A, H, LI |
| The default drill link URL. | A, H, LI, S |
| The value with default formatting and linking. | A, H, LI |
| User filters applied to the field. | A, DE, H, LA, LI |
| Start date of a date filter. | S |
| End date of a date filter. | S |
| Applies filter logic to SQL. | S |
| Value of a parameter. | DE, LA, S |
| Injects parameter value (safe for logic). | DE, H, LA, LI, S |
| User attribute value. | A, DE, H, LA, LI, S, DV, F |
| Model name. | A, DE, H, LA, LI, S |
| View name. | A, DE, H, LA, LI, S |
| Explore name. | A, DE, H, LA, LI, S |
| Field name. | A, DE, H, LA, LI, S |
| | DE, LA, LI, S |
| | DE, LA, LI, S |
| | DE, LA, LI, S |
| | DE, LA, LI, S |
_in_queryview: orders {
sql_table_name:
{% if orders.created_date._in_query or orders.created_hour._in_query %}
orders_daily_summary -- Fallback to daily partition if granular date used
{% elsif orders.created_month._in_query %}
orders_monthly_summary -- Use monthly summary for high-level queries
{% else %}
orders_all_transactions -- Default/Detail table
{% endif %} ;;
}sql_on_in_queryexplore: order_items {
join: users {
type: left_outer
sql_on: ${order_items.user_id} = ${users.id} ;;
relationship: many_to_one
}
join: user_facts {
type: left_outer
sql_on: ${users.id} = ${user_facts.user_id} ;;
relationship: one_to_one
# Only join user_facts if a field from it is actually selected/filtered
sql_where: {% if user_facts._in_query %} 1=1 {% else %} 1=0 {% endif %} ;;
}
}sql_wheresql_on{% if %}measure: dynamic_rate {
type: number
sql:
{% if users.traffic_source._is_selected %}
${total_revenue} / NULLIF(${traffic_source_count}, 0)
{% else %}
${total_revenue} / NULLIF(${total_users}, 0)
{% endif %} ;;
}dimension: status {
html:
{% if value == 'complete' %}
<span style="color: green">{{ rendered_value }}</span>
{% else %}
<span style="color: red">{{ rendered_value }}</span>
{% endif %} ;;
}view: customer_facts {
derived_table: {
sql:
SELECT customer_id, SUM(amount)
FROM orders
WHERE {% condition order_date %} created_at {% endcondition %}
GROUP BY 1 ;;
}
}view: brand_category_item {
parameter: filter { type: unquoted }
}
explore: complex_filter_parsing {
# Example: Parsing a string like "Brand1..Category1__Brand2..Category2"
# This logic splits the string by '__' then '..' to generate OR conditions
sql_where:
{% assign items = brand_category_item.filter._parameter_value | split: '__' %}
{% for item in items %}
{% assign parts = item | split: '..' %}
{% if forloop.first %} ( {% else %} OR ( {% endif %}
${products.brand} = '{{ parts[0] }}' AND ${products.category} = '{{ parts[1] }}'
)
{% endfor %}
{% if items.size == 0 %} 1=1 {% endif %}
;;
}