D
D
Daniel2017-07-30 10:52:34
PHP
Daniel, 2017-07-30 10:52:34

How to call the desired php function outside the scope of Opencart?

I hope I expressed my thoughts correctly. We have for example a page title that is dynamically generated using the following code

<h1 id="title-page"><?php echo $heading_title; ?></h1>

The scope of which is category.tpl, if you put this code in header.tpl, then there will be an error, because there is a call to header.php, and there is no such function ... how can I insert it into the header without adding this function to the header .php? Is it possible to somehow specify where to look for the heading_title function

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zoozag, 2017-08-30
@Sunrise23

how can i insert it into the header without adding this function to header.php?

Read about global variables
But judging by the question, you want to display the title not in category.tpl, but in header.tpl, or both.
To do this, in the category.php controller, find where the value of the $data['heading_title'] variable is assigned and copy this code to header.php
if (isset($this->request->get['path'])) {
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$path = '';
$parts = explode('_', (string)$this->request->get['path']);
$category_id = (int)array_pop($parts);
foreach ($parts as $path_id) {
if (!$path) {
$path = (int)$path_id;
} else {
$path .= '_' . (int)$path_id;
}
$category_info = $this->model_catalog_category->getCategory($path_id);
if ($category_info) {
$data['breadcrumbs'][] = array(
'text' => $category_info['name'],
'href' => $this->url->link('product/category' , 'path=' .$path .$url)
);
}
}
} else {
$category_id = 0;
}
$category_info = $this->model_catalog_category->getCategory($category_id);
if ($category_info) {
if ($category_info['meta_h1']) {
$data['heading_title'] = $category_info['meta_h1'];
}
}
Or work through $this->document->
For example, see how the title of the page is passed.

P
Pavel Kornilov, 2017-07-30
@KorniloFF

Try to call it as a method of your class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question