我需要将数据从 .phtml 中的块创建位置发送到我的 CMS 块。
我在 .phtml 上创建块,如下所示
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$category = $objectManager->get('MagentoFrameworkRegistry')->registry('current_category'); ?>
<?php if ($category->getShortDescription()) : ?>
<?php echo $block->getLayout()->createBlock(
'MagentoCmsBlockBlock')->setBlockId('short_description')->setData('sd','Hello Short')->toHtml();?>
<?php endif; ?>
在这里,我将一个参数传递给块作为setData('sd','Hello Short')
但是该参数未显示在cms块上
我在我的博客上称这个参数/参数为
The Short Description is {{sd}}
但我希望输出应该是The Short Description is Hello Short
但我The Short Description is {{sd}}
我已经通过替换CMS块上的文本来解决此问题。
<?php if ($category->getShortDescription()) : ?>
<?php
$shortDescriptionBlock = $block->getLayout()->createBlock(
'MagentoCmsBlockBlock',"",["short_desc" => $category->getShortDescription()])->setBlockId('short_description')->toHtml();
echo str_replace("{{short_description}}", $category->getShortDescription(), $shortDescriptionBlock);?>
<?php endif; ?>