Learn how to use data from a GraphQL query in your website pages.
dataQueryPath
template annotation and provide the path to the associated GraphQL query file. You don’t need to include the file’s .graphql extension in the path.
For example, if you want to bind a query file to a template that renders the query’s results on the page, the top of your template’s code would include the following:
data_query
variable in HubL. The example below defines a HubL variable to store available roles:
data_query
variable. The example below defines a HubL variable to store the queried data for a collection of contacts:
data_query_path
parameter in your module’s meta.json file. It’s recommended you define your module within a modules directory at the root of your theme to make it easier to reference your query with a relative path.
data_query_path
parameter and specify the path to the associated GraphQL query file, relative to the location of the meta.json file. For example, if the query file is in a data-queries directory at the root of your theme, your meta.json file would include the following:#
character. The convention for GraphQL variable names is to prefix them with a $
character. For example, to define a variable for the ID of a contact:# $contact_id = "{{ request.contact.contact_vid || ''}}"
!
after its type. To pass the $contact_id
variable above into a query to show contact info for a given contact, your query definition would begin with:query contact_info($contact_id: String!)
$contact_id
variable from above, the query below would provide the first name, last name, and email of a contact visiting a page:request.query_dict
HubL variable. For example, if you have a page URL that contained /contacts?location=Boston&department=marketing, and wanted to use the URL query parameters in your GraphQL query to filter contacts by location and department, you could use the following GraphQL query:Dynamic page directive | Description |
---|---|
web_page_canonical_url | The canonical URL of the page |
web_page_featured_image | The page’s featured image, which will appear when the page is shared. |
web_page_meta_description | The page’s meta description |
web_page_title | The page’s title |
"hasUniqueValue": true
. Existing properties cannot be updated to have this parameter, so you’ll need to create a new property through the API if you don’t already have one.
label
and description
for your query as single line comments at the top of your query. Then add another single line comment for an identifier to associate with the dynamic slug of your page:
dynamic_slug
field provided by the request.path_param_dict
HubL variable.profile_full_name
as the slug for each contact’s profile page, the following comment would be included above the query definition:#$profile_full_name: {{ request.path_param_dict.dynamic_slug }}
CRM
data, include the hs_object_id
field.HUBDB
table, include the hs_id
field.@
character. For example, to configure the title, meta description, and featured image for a contact profile page:data_query
HubL variable./profiles
./profiles
, so the full content slug for the page should be /profiles/[:dynamic-slug]
.