在模块页面中显示cms页面

时间:2018-12-08 12:33:27

标签: prestashop-1.7

我在我的网站的客户服务中使用了第三方模块。 在此模块中,有一个专用页面来创建故障单。

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

为此,我在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>

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

有人可以帮我吗?

2 个答案:

答案 0 :(得分:1)

感谢@ marcin-jaworski给我个方法。

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

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

别忘了使用“ nofilter”来打印html。

答案 1 :(得分:0)

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

PrestaShop DevDocs

Displaying content on the front office

您可以通过使用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}
相关问题