- This topic is empty.
-
AuthorPosts
-
February 17, 2023 at 1:12 am #9897
Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
David Hoang
KeymasterTo render an enabled CMS block in a phtml file in Magento 2, you can use the following code:
<?php $blockId = 'your_block_identifier'; // Replace with your block identifier $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $block = $objectManager->create('Magento\Cms\Block\Block')->setBlockId($blockId); if ($block->getIsActive()) { echo $block->toHtml(); } ?>Here’s a breakdown of the code:
Define the identifier of the CMS block you want to render. This can be found in the CMS block list in the Magento admin panel.
$blockId = 'your_block_identifier';Create an instance of the CMS block using the ObjectManager
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $block = $objectManager->create('Magento\Cms\Block\Block')->setBlockId($blockId);Check if the block is active (enabled)
if ($block->getIsActive()) {If the block is active, render the block’s HTML using the toHtml() method.
echo $block->toHtml();Note that using the ObjectManager directly is not best practice, and it is recommended to use dependency injection instead. Additionally, you should make sure to sanitize the $blockId input to avoid security vulnerabilities.
February 17, 2023 at 12:05 pm #9896
Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
David Hoang
KeymasterPretty much what the title says. I want to add the google map in a cms block and then call it in a
form.phtmlfor Contact Page. How do I do it?February 24, 2023 at 5:53 am #9898
Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
David Hoang
KeymasterOverride form.phtml file in your child theme and then Call your static block in that override form.phtml file:
<?php echo $this->getLayout() ->createBlock('Magento\Cms\Block\Block') ->setBlockId('your_block_identifier') ->toHtml(); ?> -
AuthorPosts
- You must be logged in to reply to this topic.