S
S
Sergey2015-09-04 08:54:56
PHP
Sergey, 2015-09-04 08:54:56

How to display the variable I created (Opencart) on the page? What is responsible for displaying variables in the common/header.tpl file?

I need to display the name of the new (logged in) client in header.tpl. The first step I decided to go to the controller and create a variable there with random content, display it on the page. In the controller, looking at how other variables are set, I write:

$data['customer_name'] = 'Sergey';
или
$this->data['customer_name'] = 'Sergey';

I output it like echo $customer_name; in tpl. At the output I get:
Undefined variable: customer_name in /vqmod/vqcache/vq2-catalog_view_theme_default_template_common_header.tpl

I take any other variable from the controller, which is set in the same way - everything is good.
Files I edit: catalog/view/theme/default/template/common/header.tpl
/catalog/controller/common/header.php
What did I do wrong?
PS There are suspicions that not only the header.php from the controller is responsible for the output of variables in this tpl file. From where else can variables be set in this case?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
O
opencart-russia, 2015-09-12
@zeyser

First, tell me what version of OpenCart

U
urfinjazz, 2015-09-05
@urfinjazz

the error
Undefined variable: customer_name in /vqmod/vqcache/ ...
says that you should clear the cache, i.e. delete contents of vqcache

E
Evgeny Efimchenko, 2016-12-29
@clean_code

So how was the issue resolved? Same problem!

I
iurii12345, 2017-06-01
@iurii12345

In header.php

if ($this->customer->isLogged()) {
  $data['welcome_message'] = sprintf("Добро пожаловать, %s!", $this->customer->getFirstName());
    }

In header.tpl
<div><?php if (isset($welcome_message)) { echo $welcome_message; } ?></div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question