在模块页面中显示cms页面



我的网站的客户服务使用第三方模块。在这个模块中,有一个专门的页面用于创建票证。

我尝试在这个页面的左侧添加一个cms页面(已经在Pages of Prestashop中创建(。

为此,我在modules/{THEmodule}/controllers/front/function.php 中创建了一个函数

public function getFAQ($id_cms, $id_lang = null, $id_shop = null){
if (is_null($id_lang)) {
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
}
if (is_null($id_shop)) {
$id_shop = (int)Configuration::get('PS_SHOP_DEFAULT');
}

$sql = new DbFAQ();
$sql->select('content');
$sql->from('cms_lang');
$sql->where('id_cms = .(int)$id_cms.' AND 'id_lang = .(int)$id_lang.' AND 'id_shop = .(int)$id_shop');
return Db::getInstance()->executeS($sql);
}

然后我调用.tpl 中的函数

<div id="support-getFAQ">
{$getFAQ=12} {* 12 is the id of the cms page that I want display *}
</div>

但当我查看页面时,什么都没有显示,所以我想这不是一个好方法。

有人能帮我吗?

感谢@marcin jaworski给我指路。

解决方案很简单。无需添加功能,只需在tpl:中写入即可

{assign var=new_smarty_var value=CMS::getCMSContent(12)}
{$new_smarty_var.content nofilter}

不要忘记使用"nofilter"来打印html。

由于良好的实践,您应该在模块控制器或钩子的显示函数中分配smarty变量。

PrestaShop DevDocs

在前台上显示内容

您可以使用CMS类(/classes/CMS.php(中已有的功能来获取CMS内容:

public static function getCMSContent($id_cms, $id_lang = null, $id_shop = null)
public static function getCMSPages($id_lang = null, $id_cms_category = null, $active = true, $id_shop = null)

我还有一个小技巧,你可以在.tpl中使用

{assign var=new_smarty_var value=(CMS::getOneCMS(11, $language.id)}
{$new_smarty_var.content}

最新更新