Metadata
Last edit: Apr 22, 2020
Metadata is a property to store any kind of key-value pairs. A page can be extended using metadata, for example:
---
metadata:
title: "This it the title"
description: "A description"
tags: ["signup", "choose", "landing"]
---
Displaying metadata on the page
Metadata is available through Liquid as context.page.metadata:
<h1>{{ page.metadata.title }}</h1>
<section>{{ page.metadata.description }}</section>
<ul>
{% for tag in page.metadata.tags %}
<li>{{ tag }}</li>
{% endfor %}
</ul>
<strong>{{ page.metadata.tags | join: "," }}</strong>
Searching for a page using its metadata
You can search for a page using its metadata in GraphQL queries (all support page and per_page pagination arguments). Here's an example of a GraphQL query with all possible parameters.
query find_page(
$page: Int
$per_page: Int
$metadata: String
$exclude: String
$has_key: String
$name: String
$value: String
) {
pages: pages(
page: $page
per_page: $per_page
filter: {
metadata: {
contains: $metadata,
has_key: $has_key,
attribute: {
key: $name,
value: $value
},
exclude: $exclude
}
}
) {
total_entries
results {
id
slug
metadata
format
page_url
title
content
}
}
}
Some examples of using the above query from a Liquid template to find metadata:
Find pages WITH word TITLE somewhere in metadata (in keys or values)
{% graphql q = 'find_page', page: 1, per_page: 20, metadata: "TITLE" %}
Find pages WITHOUT word TITLE in metadata (in keys or values)
{% graphql q = 'find_page', exclude: 'true', metadata: "TITLE" %}
Match pages having top-level key tags
{% graphql q = 'find_page', has_key: 'tags' %}
Match pages without "tags" key
{% graphql q = 'find_page', exclude: 'true', has_key: 'tags' %}
Match pages with key tags having (or including) value bar
{% graphql q = 'find_page', name: 'tags', value: 'bar' %}
Match pages that do not have key tags equal (or including) to bar
{% graphql q = 'find_page', exclude: 'true', name: 'tags', value: 'bar' %}