如何将变量粘贴到控制器中的函数中

时间:2017-09-10 16:32:30

标签: smarty prestashop

我希望我输入正确的主题。我需要知道什么?从控制器我有我的商店的cms页面列表。然后我想获得内容,但我不知道如何。

我的控制器:

    class ProductController extends ProductControllerCore {

    public function initContent() {
        parent::initContent();
        $cmsList = CMS::listCms();
        $this->context->smarty->assign('cmsList', $cmsList);
    }

    public function getCMSContent($cmsID){
        $cmsID = CMS::getCMSContent();
        $this->context->smarty->assign('cmsContentProduct', $cmsID);
    }

}

在我的product.tpl文件中,我有:

{$productCategory = $product->category}
            {foreach from=$cmsList item=varCMS}
                {$cmsID = $varCMS.id_cms}
                {$cmdTitle = $varCMS.meta_title}
                {if $cmdTitle == $productCategory}
                    {* get contnet from CMS*}
                {/if}
            {/foreach}

如何将我的cms ID粘贴到getCMSContent?

亲切的问候

1 个答案:

答案 0 :(得分:0)

    class ProductController extends ProductControllerCore {

    public function initContent() {
        parent::initContent();
        $cmsList = CMS::listCms();
        $this->context->smarty->assign('cmsList', $cmsList);
    }

    public function getCMSContent($cmsID){
        $cms = new CMS($cmsID, intval($cookie->id_lang));
        return $cms;
    }
}

.tpl文件:

{$productCategory = $product->category}
                {foreach from=$cmsList item=varCMS}
                    {$cmsID = $varCMS.id_cms}
                    {$cmdTitle = $varCMS.meta_title}
                    {if $cmdTitle == $productCategory}
                        <section class="page-product-box">
                <h3 class="page-product-heading"></h3>
                <div class="rte"><p>{ProductController::getCMSContent($cmsID)->content[1]}</p></div>
            </section>
                    {/if}
                {/foreach}

此功能检查产品类别并与所有cms页面进行比较。如果相同则此功能显示CMS的内容。它适用于PS 1.6。

亲切的问候