A
A
Artur Svitov2021-02-22 17:50:09
opencart
Artur Svitov, 2021-02-22 17:50:09

How to display your multilingual text from the admin panel in the footer of Opencart 3?

Good afternoon, I'm racking my brains on how to display text in the footer from the admin panel:
In the default.php theme controller (in the admin panel), I added the code

if (isset($this->request->post['theme_default_footer_text'])) {
      $data['theme_default_footer_text'] = $this->request->post['theme_default_footer_text'];
    } elseif (isset($setting_info['theme_default_footer_text'])) {
      $data['theme_default_footer_text'] = $setting_info['theme_default_footer_text'];
    } else {
      $data['theme_default_footer_text'] = false;
    }

In the theme file default.twig added the code:
<div class="form-group">
                <label class="col-sm-3 control-label">Текстовый блок</label>
                <div class="col-sm-9">
                  {% for language in languages %} 
                  <div class="input-group"><span class="input-group-addon"><img src="language/{{ language.code }}/{{ language.code }}.png" title="{{ language.name }}" /></span>
                    <textarea name="theme_default_footer_text[{{ language.language_id }}][text]" rows="5" placeholder="Текстовый блок" class="form-control">{{ theme_default_footer_text[language.language_id] ? theme_default_footer_text[language.language_id].text }}</textarea>
          </div>
                  {% endfor %} 
                </div>
              </div>

Added this text to the footer controller
$data['text'] = html_entity_decode($this->config->get('theme_default_footer_text' . $this->config->get('config_language_id')), ENT_QUOTES, 'UTF-8');


In the admin panel, the text is added and saved, everything is fine, it is not displayed in the footer

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Serge Tkach, 2021-02-26
@SergeTkach

You seem to have covered everything in detail. But!
Forgot to describe how you added {{ text }} to the file "catalog/view/theme/default/template/common/footer.twig" or did you not add it there?
+
If added, did you update the twig cache?
++
Did you var_dump $data['text'] in the controller itself? Something I doubted that something was working out there.
In theory, it should be:

$text = $this->config->get('theme_default_footer_text'); // поле в таблице `oc_setting` называется именно так. А если добавить ID языка, то выйдет 'theme_default_footer_text0'

$data['text'] = $text[$this->config->get('config_language_id')];

A
Artur Svitov, 2021-02-27
@DoodleJump

Thanks Serge, I changed it to this option and it worked! Thanks again
$data['text'] = $this->config->get('theme_default_footer_text')[$this->config->get('config_language_id')];

0
0xD34F, 2017-10-28
@sizest

It'll do? -

$(document).on('click', '.question > h3', function() {
  $(this).next().toggle(200);
});

Instead of individual handlers, we hang up a common delegated one.

M
Maxim Kostyukevich, 2017-10-28
@maxisoft

Here is a variant Optimized code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question