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?
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
}