Pinned data (data_sources)
This page shows the JSON behind pinned entries and pinned queries: the data_sources items that declare them, how a query's filters are stored, and the bindings that read them. You need it when you write a composition with the Studio API, or read one that Studio saved.
The examples use the Blog project: the Blog post and Author content types, and the author entry Priya.
The data_sources array
A contentstack or contentstack_queries binding reads from data_sources. The Studio API takes data_sources as an array and stores it as a JSON string. A string or any other value that isn't an array fails with data_sources_not_array.
[
{
"uid": "contentstack",
"data": [{ "uid": "blt9f8e7d6c5b4a3210", "_content_type_uid": "author" }]
},
{
"uid": "contentstack_queries",
"data": [
{
"uid": "latest-posts",
"name": "Latest posts",
"spec": {
"contentType": "blog_post",
"sourceType": "content_type",
"query": {},
"params": { "limit": 3, "desc": "created_at" }
}
}
]
}
]
- The SDK reads a pinned entry from
dataSources.contentstackunder the key<content type uid>:<entry uid>. - An item's
uidistemplate,contentstack,contentstack_queriesorexternal_data. The API rejects any other, includingqueries, and rejects two items with the sameuid. - Each pinned entry needs both
uidand_content_type_uid. The API rejects a pinned entry with an oldreferenceslist, because it works out reference paths itself. - A query
spechas four fields:contentType,sourceType,queryandparams.sourceTypedefaults tocontent_type, and Studio writes only that value. - In
params,limit,skip,ascanddescmap to the Delivery API.descandasctake a field UID. - The SDK sends
params.includeas reference includes, but Studio removesinclude,onlyandexceptfrom the filters you type. - Studio sets a new query's
uidto its name in lowercase with spaces changed to hyphens, and keeps it when you rename the query. - A query that isn't in
data_sourcesnever runs, so a binding to itsqueryUIDshows the prop's default. The API rejects that binding withbinding_query_not_declared. - A
contentstackbinding to an entry that isn't pinned indata_sourcesgets the warningbinding_pinned_entry_not_declared. The API then adds the entry to thecontentstackitem, so the entry's references are fetched. - The SDK skips a query whose
spechas nocontentType, with no error. The API rejects it withquery_spec_invalid, and rejects two queries with the sameuid. - The content type of each pinned entry and query must exist in the stack.
- A failed query request returns
{ entries: [], count: 0 }, so the list is empty and no error shows. - A pinned entry the Delivery API doesn't return leaves its bindings on the prop's default.
- Pinned Queries need
@contentstack/studio-react1.3.0 or later, which brings@contentstack/studio-client1.5.0.
Where the filters go
The YAML you type in Input Filters splits into two parts of spec. Its query key becomes spec.query, and its params key becomes spec.params.
A variable, such as {{url.params.topic}} or {{now - 30 days}}, is stored as that exact string. Studio doesn't work out its value when you save. The SDK replaces it each time the composition renders, so the list follows the page URL and the date.
This filter, typed in Studio:
query:
taxonomies.topic:
$in:
- "{{url.params.topic}}"
created_at:
$gte: "{{now - 30 days}}"
params:
limit: 3
desc: created_at
is stored as this spec:
{
"contentType": "blog_post",
"sourceType": "content_type",
"query": {
"taxonomies.topic": { "$in": ["{{url.params.topic}}"] },
"created_at": { "$gte": "{{now - 30 days}}" }
},
"params": { "limit": 3, "desc": "created_at" }
}
- Write a variable as a whole string value, with the braces. The SDK replaces only a value that starts with
{{. - A variable the SDK doesn't know is sent as typed, and the SDK logs
Unknown expressionin the console. - On a server-rendered route,
url.paramsis empty unless you pass the request's query string. See The page URL. - For every variable and operator, see Query Input Filters.
Bind a prop to a pinned entry
A contentstack binding names the entry by uid and _content_type_uid, and the field by path. This header shows the pinned author's name.
{
"uid": "author_heading",
"type": "header",
"attrs": {},
"metadata": {},
"props": {
"text": {
"type": "string",
"binding": {
"type": "contentstack",
"value": {
"uid": "blt9f8e7d6c5b4a3210",
"_content_type_uid": "author",
"path": { "title": {} }
}
}
}
},
"slots": {},
"styles": {}
}
Repeat a card for each query result
A contentstack_queries binding reads an object with entries and count, not a bare list. A Repeater over a query reads its items from path: { "entries": {} }. path: {} works too. Each card reads the current post with a repeater binding.
{
"uid": "topic_posts_repeater",
"type": "repeater",
"attrs": {},
"metadata": { "mode": "preview" },
"props": {
"items": {
"type": "array",
"binding": {
"type": "contentstack_queries",
"value": { "queryUID": "topic-posts", "path": { "entries": {} } }
}
},
"children": { "type": "slot", "slot": "items_slot" }
},
"slots": {
"items_slot": [
{
"uid": "topic_post_card",
"type": "PostCard",
"attrs": {},
"metadata": {},
"props": {
"title": {
"type": "string",
"binding": {
"type": "repeater",
"value": { "repeaterUID": "topic_posts_repeater", "path": { "title": {} } }
}
}
},
"slots": {},
"styles": {}
}
]
},
"styles": {}
}
A Section with a pinned entry and a filtered query
This Section, Topic posts, shows Priya's name and the 3 newest posts of the last 30 days on the topic in the page URL. It has no linked schema, so it reads only its own pinned data. Send it to the /sections route as in Create a section and a template with the API.
{
"title": "Topic posts",
"composable_uid": "topic_posts",
"ui": {
"uid": "topic_posts_root",
"attrs": {},
"type": "page",
"metadata": {},
"props": {
"children": { "type": "slot", "slot": "body_slot" }
},
"slots": {
"body_slot": [
{
"uid": "author_heading",
"type": "header",
"attrs": {},
"metadata": {},
"props": {
"text": {
"type": "string",
"binding": {
"type": "contentstack",
"value": {
"uid": "blt9f8e7d6c5b4a3210",
"_content_type_uid": "author",
"path": { "title": {} }
}
}
}
},
"slots": {},
"styles": {}
},
{
"uid": "topic_posts_repeater",
"type": "repeater",
"attrs": {},
"metadata": { "mode": "preview" },
"props": {
"items": {
"type": "array",
"binding": {
"type": "contentstack_queries",
"value": { "queryUID": "topic-posts", "path": { "entries": {} } }
}
},
"children": { "type": "slot", "slot": "items_slot" }
},
"slots": {
"items_slot": [
{
"uid": "topic_post_card",
"type": "PostCard",
"attrs": {},
"metadata": {},
"props": {
"title": {
"type": "string",
"binding": {
"type": "repeater",
"value": { "repeaterUID": "topic_posts_repeater", "path": { "title": {} } }
}
}
},
"slots": {},
"styles": {}
}
]
},
"styles": {}
}
]
},
"styles": {}
},
"data_sources": [
{
"uid": "contentstack",
"data": [{ "uid": "blt9f8e7d6c5b4a3210", "_content_type_uid": "author" }]
},
{
"uid": "contentstack_queries",
"data": [
{
"uid": "topic-posts",
"name": "Topic posts",
"spec": {
"contentType": "blog_post",
"sourceType": "content_type",
"query": {
"taxonomies.topic": { "$in": ["{{url.params.topic}}"] },
"created_at": { "$gte": "{{now - 30 days}}" }
},
"params": { "limit": 3, "desc": "created_at" }
}
}
]
}
],
"static_value": {
"text": [],
"href": [],
"imageurl": []
},
"linked_schemas": []
}
- Replace
blt9f8e7d6c5b4a3210with the UID of an entry in your stack, andPostCardwith a component you registered. - Every
contentstackandcontentstack_queriesbinding has a matching item indata_sources. The API doesn't check this, and a binding with no item shows the prop's default. - The pinned data belongs to the Section. Every Template that places it shows the same author and the same query, and the Template's own
data_sourcesdoesn't list them.
Which composition reads which pinned data
| Composition | Its pinned entries and queries |
|---|---|
| Connected Template | Its own data_sources |
| Freeform Template | Its own data_sources |
| Section | Its own data_sources. They apply wherever the Section is placed. |
For every value source and composition kind, see Which sources each kind of composition has.