Get CMS Block Collection in Magento 2.

You can get all the CMS Static Blocks collection in Magento 2 by calling interface, Magento\Cms\Api\BlockRepositoryInterface.

Magento\Cms\Api\BlockRepositoryInterface used for getting CMS Static Blocks related data in Magento 2.

BlockRepositoryInterface is used when you need to fetch a collection of CMS Static blocks or get specific CMS static block data. You can get Specific Blocks data by Identifier using  Get Cms Blocks data by an identifier.

Continue reading “Get CMS Block Collection in Magento 2.”

Get CMS Block content by identifier in Magento 2.

You can get the CMS Static Blocks collection by an identifier in Magento 2 by calling the BlockRepositoryInterface interface.

Magento\Cms\Api\BlockRepositoryInterface is used for getting CMS Static Blocks in Magento 2.

BlockRepositoryInterface is used when you need to fetch a collection of CMS Static blocks or get specific CMS static block data.

Continue reading “Get CMS Block content by identifier in Magento 2.”

Ajax response from controller file Magento 2

To pass Ajax response from the controller in Magento 2, You need to use Magento\Framework\Controller\Result\JsonFactory Object.

Many times your custom functionality requires you to use Ajax request on a page to display information without any page load and in this situation, you need to know about Ajax use in Magento 2 to achieve your requirement.

Magento\Framework\Controller\Result\JsonFactory is used for sending a response from a controller to an Ajax request.

Pass your response in the setData() method. Continue reading “Ajax response from controller file Magento 2”