how to add hooks to cms pages in prestashop 1.7

Viewed 950

I am discovering PrestaShop 1.7 and am trying to add a module to a specific CMS page.

However, CMS pages don't let me run any smarty code which means I can't call any of my hooks.

What I would usually add to put a module somewhere:

    {hook h='displayMyhook'}

I have seen solutions for 1.6 but they all revolve around editing "CMS.tpl" which doesn't seem to exist in 1.7.

Could anyone suggest a solution?

1 Answers

Hook Creation:

public function install()
{
    return parent::install()
        && $this->registerHook('diplayAccessoryExtraProduct')
        && $this->registerHook('displayModalContent');
}

You can create a hook, with the name of your choice: displayMyNewHook

Show hook in (any) tpl file:

{block name='diplayAccessoryExtraProduct'}
    {hook h='diplayAccessoryExtraProduct' id_product=$product.id_product mod="mymodule"}
{/block}

or (no value for function)

{block name='diplayAccessoryExtraProduct'}
    {hook h='diplayAccessoryExtraProduct' mod="mymodule"}
{/block}

Function in the module:

public function hookDiplayAccessoryExtraProduct($params)
{
    $accessories = $this->getAccessories((int)$params['id_product']);
    $this->context->smarty->assign(array(
                'accessories_custom' => $accessories,    
        )
    );
    return $this->display(__FILE__, 'views/templates/front/accessory.tpl');
}

public function getAccessories($id_product)
{
    // Code
    return $result;
}

This is a real example of a module I have developed.

Related