T
T
tyoma_koder2022-01-14 15:17:52
opencart
tyoma_koder, 2022-01-14 15:17:52

How to insert tag in head by condition in category controller?

There is a variable in the category controller that is not available in the header controller, you need to insert a tag into the head tag with a certain value of this variable.
I tried to pass this variable from the category controller to $this->document, but it did not work out - in the header it = null

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
opencartbot, 2022-01-16
@opencartbot

We need to make a series of improvements.
In the system/library/document.php file,
add handlers:

private $myTag = array();
public function addMyTag($var) {
  $this->myTag[] = $var;
}
public function getMyTag() {
  return $this->myTag;
}

In the catalog/controller/common/header.php file, add data acquisition: In the catalog/view/theme/*/template/common/header.twig file , add the output of the html code to the right place in the head block:
$data['myTag'] = $this->document->getMyTag();
{% for tag in myTag  %}
{{ 'любой ваш html код или переменная '~tag }}
{% endfor %}

Now from the category controller you can pass data to head with this line:
$this->document->addMyTag($var);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question