Skip to content

Lookup variables

Lookup variables let supported Definer fields use details that change with each lookup. For example, a Custom source can add the lookup text or page title to its URL, Custom Audio can build an audio URL, and an AI prompt can include text around the lookup. The same values are available in supported Routine fields and the Script source.

Recipes use a different set of values for the lookup and source result, which they use to create a Collection item. See Use Liquid in Recipes when you are editing a Recipe.

Use a variable

Custom source URLs, AI prompts, and supported Routine fields use Liquid. Put a variable name between {{ and }}, such as {{ str }} for the lookup text.

In a Custom source URL

Open Definer Options → Sources, select the Custom source you want to change, then expand Settings. Enter the following address in URL to open a Wikipedia search for the lookup text:

liquid
https://en.wikipedia.org/w/index.php?search={{ str | url_encode }}

The url_encode filter makes spaces and other special characters safe inside the URL. Run a lookup for solar energy with this source and check that it opens a URL ending in search=solar%20energy.

Wikipedia URL in a Custom source with the Variables list expanded

In an AI prompt

Open Definer Options → Sources, select the AI source you want to change, expand Settings, then select Prompts. Create or edit a prompt and enter this content to give the model the lookup text and an optional surrounding paragraph:

liquid
Explain "{{str}}" clearly and briefly in {{lang | language_label: "both"}}.
{{ paragraph | mark: paragraph_range | with_prefix: "Context:", newline }}

Open Playground below the prompt. Set str to "bank" and lang to "en". Select Add variable, then add paragraph with "The bank raised its fees, but she sat on the bank of the river." and paragraph_range with {"start":45,"end":49}. The preview should show literal <mark> tags around the second occurrence:

text
Explain "bank" clearly and briefly in English.
Context:
The bank raised its fees, but she sat on the <mark>bank</mark> of the river.

If you remove paragraph_range or enter a range outside the paragraph, the preview should contain only the first line. The mark filter returns nothing when it does not receive a valid range, and with_prefix omits the context label with it. See Liquid filters for the complete behavior and more optional-context patterns.

The screenshots below show the same prompt editor and Playground with another context template.

An AI prompt named Context explainer using the lookup text, sentence, and page title variables

The prompt Playground rendering renewable, its surrounding sentence, and the Clean Energy Basics page title

In a Routine

Routine Input values and Extract → Liquid Template transformations accept the same {{ variable }} form. See Routine Steps for the fields and their surrounding workflow.

In a Script source

Open Definer Options → Sources, select the Script source you want to change, then expand Settings. In the JavaScript field, select the outward-arrow Maximize control. The full editor's Variables panel shows and copies the complete definer.lookup.getVariable('name') expression for each value. See Use Lookup variables in Script for Script-specific rules.

Find variables in Definer

The Variables section below a Custom URL, AI prompt, or supported Routine field starts with common values. Select Show all to search every Lookup variable and read its description.

You can also type {{ in a Liquid field to open variable suggestions. Continue typing part of a name, then choose the matching suggestion.

Variable search results for sentence, page title, and links beside Liquid autocomplete

Choose the right language variable

Several variables describe a language, but each answers a different question:

VariableUse it forExample
langThe language of the active lookup result.en
langsAll result languages available in the lookup.["en", "fr"]
src_langThe detected language of the lookup text.jpn
page_langThe language declared by the website.ja
ui_langDefiner's interface language.en
browser_localeThe browser's locale.en-US

Use src_lang when a prompt or URL should react to the language of the lookup text. Use lang when it should react to the result language chosen in Definer.

Work with lists and objects

Most variables contain one string, number, or true/false value. Some contain a list or an object with named properties.

Use first when you need only the first item in a list:

liquid
First section: {{ h2 | first }}

Use brackets and a property name to read part of a list item or object:

liquid
First link: {{ links[0].text }} -> {{ links[0].href }}
Selection starts at: {{ sentence_range.start }}
Detected language: {{ src_lang_info.name }}

Use a loop when you want several items:

liquid
{% for heading in h2 limit: 3 %}
- {{ heading }}
{% endfor %}

The reference below uses string[] for a list of strings and object[] for a list of objects.

Lookup variable reference

The examples below show representative values. A page can produce different content, metadata, dimensions, and language results.

Lookup text and languages

VariableTypeWhat it containsExample
strstringText used for the lookup.components
char_countnumberNumber of characters in str.10
word_countnumberNumber of whitespace-separated words in str.1
langstringActive result language code.en
lang_infoobjectDetails about lang: code, base, iso6393, iso6392, name, nativeName, and any available script, region, or variants.{"code":"en","base":"en","iso6393":"eng","iso6392":"eng","name":"English","nativeName":"English"}
lang_namestringEnglish name of lang.English
lang_nativestringNative name of lang.English
langsstring[]Result language codes available in the lookup.["en", "fr"]
langs_infoobject[]One language-info object for each value in langs.[{"code":"en","name":"English",...}]
langs_namesstring[]English names of the available result languages.["English", "French"]
langs_nativestring[]Native names of the available result languages.["English", "français"]
browser_localestringLocale reported by the browser.en-US
ui_langstringDefiner interface language code.en
ui_lang_infoobjectLanguage-info object for ui_lang.{"code":"en","name":"English",...}
ui_lang_namestringEnglish name of the interface language.English
ui_lang_nativestringNative name of the interface language.English
src_langstringDetected lookup-text language as an ISO 639-3 code.jpn
src_lang_infoobjectLanguage-info object for src_lang.{"code":"jpn","base":"jpn","iso6393":"jpn","iso6392":"jpn","name":"Japanese","nativeName":"日本語"}
src_lang_namestringEnglish name of the detected lookup-text language.Japanese
src_lang_confidencenumberDetection confidence from 0 to 100.99
src_lang_reliablebooleanWhether the language detector considers its result reliable.true

Page address and metadata

The URL variables describe the page where the lookup began. query is the page URL's query string, not the text being looked up.

VariableTypeWhat it containsExample
urlstringComplete page URL.https://developer.mozilla.org/en-US/docs/Web/API/Selection?view=all#Examples
pathstringURL path./en-US/docs/Web/API/Selection
originstringProtocol and domain, including an explicit port.https://developer.mozilla.org
domainstringPage hostname.developer.mozilla.org
protocolstringURL protocol, including its colon.https:
querystringURL query string, including ?, or an empty string.?view=all
hashstringURL fragment, including #, or an empty string.#Examples
portstringExplicit URL port, or an empty string.39091
page_titlestringPage title.Selection - Web APIs | MDN
page_descstringPage description metadata.A Selection object represents the range of text selected by the user...
page_keywordsstringPage keywords metadata.Definer, Liquid, variables
page_langstringLanguage declared by the page.ja
page_dirstringText direction declared by the page.rtl
page_last_modifiedstringLast-modified metadata provided by the page.Tue, 20 Aug 2024 10:00:00 GMT
page_faviconstringBest available page icon URL.https://en.wikipedia.org/static/favicon/wikipedia.ico
page_og_titlestringOpen Graph title.Open Graph protocol
page_og_descstringOpen Graph description.The Open Graph protocol enables any web page to become a rich object...
page_og_imagestringOpen Graph image URL.https://ogp.me/logo.png
page_og_localestringOpen Graph locale.en_US
page_og_site_namestringOpen Graph site name.MDN Web Docs
page_og_urlstringOpen Graph canonical URL.https://developer.mozilla.org/en-US/docs/Web/API/Selection
page_og_typestringOpen Graph content type.website

Lookup and surrounding text

Range objects contain start and end positions. end is the first character after the matched lookup text. A range can be null when Definer cannot place the lookup text inside the surrounding value.

VariableTypeWhat it containsExample
sentencestringSentence containing the lookup text.The controlled selection appears in this sentence.
sentence_rangeobject or nullPosition of the lookup text inside sentence.{"start":4,"end":24}
sentencesstring[]Sentences found in the surrounding paragraph.["Earlier sentence.", "The controlled selection appears in this sentence.", "Later sentence."]
paragraphstringParagraph containing the lookup text.Earlier sentence. The controlled selection appears in this sentence. Later sentence.
paragraph_rangeobject or nullPosition of the lookup text inside paragraph.{"start":22,"end":42}
node_textstringText in the page text node that contains the selection. to render lists of components.
node_parent_textstringText in that node's parent page element.You will rely on JavaScript features ... to render lists of components.
node_ancestorsobject[]Up to 10 containing page elements with tagName, id, classes, attributes, and innerText.[{"tagName":"p","id":"intro","classes":["summary"],...}]
text_beforestringPage text before the selection....Earlier sentence. The
text_afterstringPage text after the selection. appears in this sentence. Later sentence...
lines_selectedstring[]Text lines touched by the selection.["chosen words"]
lines_abovestring[]Up to 25 lines above the selection.["Alpha line.", "Second line contains "]
lines_belowstring[]Up to 25 lines below the selection.[".", "Third line.", "Fourth line."]

Page content and structure

Link and image addresses are returned as written by the page. They can be complete URLs or relative paths such as /docs. A missing href, src, or alt value is null.

VariableTypeWhat it containsExample
page_textstringVisible text collected from the page body.Learn React\nQuick Start\nCreating and nesting components...
h1, h2, h3, h4, h5, h6string[]Text from headings at the corresponding level.h2: ["Quick Start", "Displaying data"]
linksobject[]Page links with text (string) and href (string or null).[{"text":"Examples","href":"#examples"}]
imagesobject[]Page images with src and alt (string or null).[{"src":"/logo.svg","alt":"MDN"}]
quotesstring[]Text from block quotes.["Quoted controlled text."]
code_blocksstring[]Text from preformatted code blocks.["const controlled = true"]
table_of_contentsobject[]Flat heading list with text, id, and level.[{"text":"Examples","id":"examples","level":2}]
document_outlineobject[]Nested heading tree with level, text, id, and children.[{"level":1,"text":"Introduction","id":"intro","children":[...]}]

page_text describes visible page text, not values entered into form fields.

Date, time, and generated values

Date and time values describe the local date and time when the lookup begins. datetime_iso is expressed in UTC. Each random value is generated once for the lookup, so repeated uses of the same variable return the same value.

VariableTypeWhat it containsExample
datetime_isostringDate and time in ISO 8601 format.2026-08-22T11:08:27.745Z
datestringLocal date in YYYY-MM-DD format.2026-08-22
timestringLocale-formatted local time.2:08:27 PM
timestampnumberMilliseconds since the Unix epoch.1787396907745
timezonenumberLocal-to-UTC offset in minutes. Negative values are ahead of UTC.-180
weekdaynumberDay of the week from 0 (Sunday) to 6 (Saturday).6
monthnumberMonth from 0 (January) to 11 (December).7
yearnumberFull local year.2026
daynumberLocal day of the month.22
hournumberLocal hour from 0 to 23.14
minutenumberLocal minute.8
secondnumberLocal second.27
millisecondnumberLocal millisecond.745
random_numbernumberRandom integer from 0 to 999.153
random_stringstringShort generated base-36 text.5r1769

Viewport

Viewport values describe the page when the lookup begins. They do not update as you continue scrolling or resize the page.

VariableTypeWhat it containsExample
scroll_pxnumberVertical scroll position in pixels.5156
scroll_percentnumberApproximate vertical scroll percentage.40
window_widthnumberPage viewport width in pixels.1440
window_heightnumberPage viewport height in pixels.960

When a value is empty

A website might not provide description, Open Graph, direction, last-modified, or other metadata. A page without matching headings, links, images, quotes, or code blocks produces an empty list for that category.

Surrounding-text values can also be empty when a lookup was typed instead of started from page text, or when the page does not expose suitable surrounding content. In Liquid, an unavailable value normally produces no text. In Script, getVariable() returns undefined, so your code can provide a fallback.