Jermain
Jermain

Reputation: 41

How do I use variables in a different place?

I'm trying to use a variable in a different place but it doesn't seem to be working.

Basically the idea that we had is to use the data you assign in the admin panel for your contact info that will be displayed on the contact page onto our footer. But whenever we try to use {{ location.adress }} in our footer.twig file it returns nothing.

Upvotes: 2

Views: 60

Answers (2)

focus.style
focus.style

Reputation: 6760

To insert anything in view in .twig file you have to determine it in corresponding controller file, like @K. B. said.

In this particular case open /catalog/controller/common/footer.php

Find

$data['newsletter'] = $this->url->link('account/newsletter', '', true);

Add after

$data['address'] = nl2br($this->config->get('config_address'));

Now open /catalog/view/theme/YOUR_THEME/template/common/footer.twig

And place anywhere you need

{{ address }}

Than clear TWIG cache. Done. Now the address from the settings is in your footer.

Upvotes: 1

K. B.
K. B.

Reputation: 1430

If you wish to retrieve some data in your template, you must declare that data in corresponding controller file. For example if need retrieve {{ address }} it should be declared $data['address'] = 'data_retrieved_from_db'; For admin and for catalog are different files.

Upvotes: 0

Related Questions