php Magento如何将Widget标签转换为HTML

yhived7q  于 2023-10-15  发布在  PHP
关注(0)|答案(1)|浏览(137)

我已经看到,当小部件被添加到一个特定的页面和文本编辑器是采取它显示

{{widget type="Magento\\CatalogWidget\\Block\\Product\\ProductsList" products_per_page="8" products_count="8" template="product/widget/content/grid.phtml" conditions_encoded="a:2:[i:1;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Combine`;s:10:`aggregator`;s:3:`all`;s:5:`value`;s:1:`1`;s:9:`new_child`;s:0:``;]s:4:`1--1`;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Product`;s:9:`attribute`;s:3:`sku`;s:8:`operator`;s:2:`()`;s:5:`value`;s:60:`WS12, WT09, MT07, MH07, 24-MB02, 24-WB04, 241-MB08, 240-LV05`;]]"}}

如何将其转换为html

aemubtdh

aemubtdh1#

我发现这个博客,我在Magento 2.4.3-p1测试它,它的作品!
https://www.rohanhapani.com/how-to-convert-cms-page-content-to-html-in-magento-2/

/**
 * Created By : Rohan Hapani
 */

/**
 * @var \Magento\Cms\Model\Template\FilterProvider
 */
protected $_filterProvider;

/**
 * @var \Magento\Store\Model\StoreManagerInterface
 */
protected $_storeManager;

/**
 * @param \Magento\Cms\Model\Template\FilterProvider $filterProvider
 * @param \Magento\Store\Model\StoreManagerInterface $storeManager
 */
public function __construct(
    \Magento\Cms\Model\Template\FilterProvider $filterProvider,
    \Magento\Store\Model\StoreManagerInterface $storeManager
) {
    $this->_filterProvider = $filterProvider;
    $this->_storeManager = $storeManager;
}

/**
 * Static block $content
 */
public function getContentFromStaticBlock($content)
{
    $storeId = $this->_storeManager->getStore()->getId();
    return $this->_filterProvider->getBlockFilter()->setStoreId($storeId)->filter($content);
}

现在,调用您的模板文件以使用HTML内容:

<?php echo $block->getContentFromStaticBlock($content); ?>

全部学分:罗汉哈帕尼

相关问题