简体   繁体   中英

How to add variable into controller/header.php

I have this site and I want to put some in header for SEO purposes. The H1 must contain manufacturer name (brand) and product code (model).

So the problem is that I'm not sure how to put this variables in controller's file so I could call them in template file next.

Any ideas? :)

The best way around this would be to edit the product controller

catalog/controller/product/product.php

and change the heading there. It's set with

$this->document->setTitle($product_info['name']);

so you just need to prepend/append the manufacturer name there, such as

$this->document->setTitle($product_info['name'] . ' ' . $product_info['manufacturer']);

Did it! Added this code to controller/common/header.php

if (isset($this->request->get['product_id'])) {
        $product_id = $this->request->get['product_id'];
    } else {
        $product_id = 0;
    }

    $this->load->model('catalog/product');

    $product_info = $this->model_catalog_product->getProduct($product_id);

    $this->data['product_info'] = $product_info;

    if ($product_info) {

        $this->data['manufacturer'] = $product_info['manufacturer'];
        $this->data['model'] = $product_info['model'];

    }

And this to theme/default/template/common/header.tpl

<?php echo $product_info['manufacturer']; ?> <?php echo $product_info['model']; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM