在模块页面中显示 cms 页面

Display cms page in a module page

我使用第 3 方模块作为我网站的客户服务。 在这个模块中,有一个专门的页面来创建工单。

我尝试在这个页面的表单左侧添加一个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>

但是我查看页面时,没有任何显示,所以我想这不是个好方法。

有人可以帮我吗?

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

PrestaShop DevDocs

Displaying content on the front office

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

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}

感谢@marcin-jaworski 给我指路。

解决方法很简单。 不用加函数,只写tpl:

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

不要忘记 "nofilter" 打印 html。