Magento2 将变量从phtml传递到Magento 2中的CMS块
我需要将数据从.phtml中的块创建位置发送到我的CMS块 我在.phtml上创建块,如下所示Magento2 将变量从phtml传递到Magento 2中的CMS块,magento2,Magento2,我需要将数据从.phtml中的块创建位置发送到我的CMS块 我在.phtml上创建块,如下所示 <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $category = $objectManager->get('Magento\Framework\Registry')->registry('current_category'); ?> <?p
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $objectManager->get('Magento\Framework\Registry')->registry('current_category'); ?>
<?php if ($category->getShortDescription()) : ?>
<?php echo $block->getLayout()->createBlock(
'Magento\Cms\Block\Block')->setBlockId('short_description')->setData('sd','Hello Short')->toHtml();?>
<?php endif; ?>
但是我希望输出应该是
简短描述是Hello Short
,但是我简短描述是{{{sd}}
我通过替换CMS块上的文本解决了这个问题
<?php if ($category->getShortDescription()) : ?>
<?php
$shortDescriptionBlock = $block->getLayout()->createBlock(
'Magento\Cms\Block\Block',"",["short_desc" => $category->getShortDescription()])->setBlockId('short_description')->toHtml();
echo str_replace("{{short_description}}", $category->getShortDescription(), $shortDescriptionBlock);?>
<?php endif; ?>
<?php if ($category->getShortDescription()) : ?>
<?php
$shortDescriptionBlock = $block->getLayout()->createBlock(
'Magento\Cms\Block\Block',"",["short_desc" => $category->getShortDescription()])->setBlockId('short_description')->toHtml();
echo str_replace("{{short_description}}", $category->getShortDescription(), $shortDescriptionBlock);?>
<?php endif; ?>