'Change meta_tags meta_description and meta_name to a custom page which extends page.tpl in Prestashop 1.7

I have a custom module which defines a custom page in Prestashop. It consist on a template which extendes page.tpl and a front controller.

I would like to understand where shall I modify the metas for this specific page.

I see in this controller this part where the template is invoked:

    $this->context->smarty->assign(array(
        'link' =>            $this->context->link,
        'category'             => $this->category,
        'main_category_logo' => $image_url,
        'description_short'    => Tools::truncateString($this->category->description, 350),
        'sub_categories'    => $data,
        'body_classes'         => array($this->php_self.'-'.$this->category->id, $this->php_self.'-'.$this->category->link_rewrite),
        'search_url' => $this->context->link->getPageLink('search', null, null, null, false, null, true)
    ));

    $this->setTemplate('module:'.$this->module->name.'/views/templates/front/category.tpl');

Is this the right place to add the metas? How this shall be done?



Solution 1:[1]

In PS 1.7 that's really easy modifying it in the tpl of a front controller.

{extends file='page.tpl'}

{block name='head_seo_title'}
    MY META TITLE
{/block}

{block name='head_seo_description'}
    MY META DESCRIPTION
{/block}

{block name='head_seo_keywords'}
    MY META KEYWORDS
{/block}

And here another option from SEO & URL from the back office: How to change meta title in prestashop module?

Solution 2:[2]

in PrestaShop 1.7, you also can create your own getTemplateVarPage() function in your ModuleFrontController class, calling the parent and set the meta variables as you want (useful for an item page type like blog article, news, store, ...), so you don't have to put logic in your template.

public function getTemplateVarPage()
{
    $page = parent::getTemplateVarPage();

    $page['meta']['title'] = 'MY META TITLE';
    $page['meta']['description'] = 'MY META DESCRIPTION';
    $page['meta']['keywords'] = 'MY META KEYWORDS';
    $page['meta']['robots'] = 'index'; // noindex, nofollow, none, ...

    return $page;
}

If it's a static page like a list or a mono page, you can add the controller and set the Meta information directly in the Back Office (SEO menu).

Good luck

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rolige
Solution 2 Agnonym