3

Can I initialize some variable in product controller product.php, then load it to header controller header.php and use it in view header.twig, to load certain information based on this variable? If not, how can I determine whether the page with the product is open or not?

focus.style
  • 5,674
  • 4
  • 18
  • 34

1 Answers1

2

Easiest way determine product page in header.php

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

} else {
    $product_id = 0;
}

if ($product_id) {
//... some code for product page
}

Also you can combine check with product controller route in header.php

if (isset($this->request->get['route']) && $this->request->get['route'] == 'product/product' && isset($this->request->get['product_id'])) {
// some code for product page
}
OcPh
  • 71
  • 3