Magento 2 How to get CMS Block in GraphQL

All developers know that CMS Blocks can be used to display promotional banners, sale blocks, return policies, or important information messages on some sections of the store, etc. In this tutorial, we'll discuss how to get CMSBlocks in GraphQL. The CMSBlocks query returns information about blocks.

Syntax

  • Get only one CMSBlock

    cmsBlocks(identifiers: String): CmsBlocks
    
  • Get multiple CMSBlock

    cmsBlocks(identifiers: [String,String]): CmsBlocks
    

The following query returns information about "Login Data" CMSBlock.

Request

saveCopyzoom_out_map
{ cmsBlocks(identifiers: "login-data") { items { identifier title content } } }

Response

saveCopyzoom_out_map
{ "data": { "cmsBlocks": { "items": [ { "identifier": "login-data", "title": "Login Info Block", "content": "<div class=\"message info\" style=\"margin-top: 50px;\">\n <p><strong>Try Demo Customer Access</strong></p>\n <p><span style=\"display:inline-block; width: 80px; padding-right: 10px;\">Email:</span>roni_cost@example.com</p>\n <p><span style=\"display:inline-block; width: 80px; padding-right: 10px;\">Password:</span>roni_cost3@example.com</p>\n</div>" } ] } } }

That's it!!

If you are looking for more GraphQL solutions then check out our another article which is List of GraphQL Queries and Mutations for Magento 2.

I hope this article helps you to find what you were looking for.

Bookmark it for your future reference. Do comment below if you have any other questions on that.

P.S. Do share this article with your team.




Recent Articles
Tags
Newsletter
Chrome Extension
Copyright © 2024 devhooks.in All rights reserved.
Ads OFF toggle_off
wifi_off