data-src=../../../../includes/paas-only.md
dynamicBlocks query
The dynamicBlocks query returns a list of dynamic blocks that have been placed in a Dynamic Blocks Rotator inline widget and meet the specified criteria.
data-variant=info
data-slots=text
When a Dynamic Blocks Rotator inline widget is created, the administrator can select the following options:
- Specified Dynamic Blocks
- Cart Price Rule Related
- Catalog Price Rule Related
Widgets defined with the Specified Dynamic Blocks option affect CMS page rendering. The other two options are used for rendering cart, product, and catalog pages and are not applicable for PWA applications. Therefore, in most cases for a CMS page, your query should assign the value of SPECIFIED to the type input attribute.
data-variant=info
data-slots=text
The following input fields are available only if specialized modules have been installed:
audience_id fieldmagento/audiences module only.cart_idmagento2-pwa-commerce module only.product_uidmagento2-pwa-commerce module only.If the magento/audiences module is installed, the following field can be returned:
DynamicBlocks.audience_idmagento/audiences module only.Syntax
dynamicBlocks(
input: DynamicBlocksFilterInput
pageSize: Int
currentPage: Int
): DynamicBlocks!
Reference
The dynamicBlocks reference provides detailed information about the types and fields defined in this query.
Example usage
The following query returns all dynamic blocks of type SPECIFIED. The returned item is a dynamic block containing only text. The second item contains a PNG file.
Request:
{
dynamicBlocks(input:
{
type: SPECIFIED
})
{
items {
uid
content {
html
}
}
page_info {
current_page
page_size
total_pages
}
total_count
}
}
Response:
{
"data": {
"dynamicBlocks": {
"items": [
{
"uid": "MQ==",
"content": {
"html": "<h2><strong>SAVE 20%</strong></h2>\r\n<p>(some restrictions apply)</p>\r\n<p> </p>"
}
},
{
"uid": "Mg==",
"content": {
"html": "<p><img src=\"{{media url="wysiwyg/save20.png"}}\" alt=\"save 20% red\"></p>"
}
}
],
"page_info": {
"current_page": 1,
"page_size": 20,
"total_pages": 1
},
"total_count": 2
}
}
}
cmsPage query response:
The following code illustrates the definition of the dynamic block with the uid of MQ==, as returned by the cmsPage query. The response has been reformatted for readability.
<div class=\"widget block block-banners\"
data-bind=\"scope: 'banner'\"
data-banner-id=\"833e4819d6c46ab41e9910f17dc04f72329cb84f1b0dc3aa76d43bcb11d605a6\"
data-types=\"\"
data-display-mode=\"fixed\"
data-ids=\"1\"
data-rotate=\"\"
data-store-id=\"1\"
data-uids=\"MQ==\">\n
<ul class=\"banner-items\"
data-bind=\"afterRender: registerBanner\">\n
<!-- ko foreach: getItems833e4819d6c46ab41e9910f17dc04f72329cb84f1b0dc3aa76d43bcb11d605a6() -->\n
<li class=\"banner-item\"
data-bind=\"attr: {'data-banner-id': $data.bannerId}\">\n
<div class=\"banner-item-content\" data-bind=\"bindHtml: $data.html\"></div>\n
</li>\n
<!-- /ko -->\n
</ul>\n
</div>