2

I have try following code for custom block. it is working fine when I does add content from admin. but, just issue for special character.

admin\view\template\extension\module\theme_module.twig

<div class="tab-content">
                    {% for language in languages %}
                    <div id="tab8-language-{{ language.language_id }}" class="tab-pane">
                      <div class="form-group">
                        <div class="col-sm-10">
                        <textarea name="custom_block[{{ language.language_id }}][description]" data-toggle="summernote" data-lang="{{ summernote }}" class="form-control" id="input-description8{{ language.language_id }}">{{ custom_block[language.language_id].description ? custom_block[language.language_id].description }}</textarea>
                        </div>
                      </div>
                    </div>
                    {% endfor %}
                  </div>

admin\controller\extension\module\theme_module.php

if (isset($this->request->post['custom_block'])) {
            $data['custom_block'] = $this->request->post['custom_block'];
        } else {
            $data['custom_block'] = $this->config->get('custom_block');
}

catalog\controller\common\header.php

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

catalog\view\theme\default\template\common\header.twig

{% set lang = config_language_id %}    
{% if custom_block[lang]['description'] %}
       {{ custom_block[lang]['description'] | convert_encoding('UTF-8', 'HTML-ENTITIES') }}
    {% endif %}

when I does add content something like from admin: ľščťžýáíé

So, does Output: ľšÄťžýáíé

user8302249
  • 91
  • 1
  • 9

2 Answers2

2

The correct way is to do this in the controller file. For example in:

catalog\controller\product\category.php

Create your variable:

$data['my_var'] = html_entity_decode($data['my_var'][$this->config->get(‌​'config_language_id'‌​)]['description'], ENT_QUOTES, 'UTF-8');

And in catalog\view\theme\default\template\product\category.twig, echo it:

{{ my_var }}

Output:

ľščťžýáíé

user8302249
  • 91
  • 1
  • 9
DigitCart
  • 2,980
  • 2
  • 18
  • 28
  • I have try your way. but then, does nothing get data. please check again my question. I have again specify in detail with my code. Thanks. – user8302249 Jan 03 '18 at 12:33
  • I have try with your code in controller. `$data['custom_block'] = html_entity_decode('custom_block', ENT_QUOTES, 'UTF-8');` but, then, does not get nothing content. – user8302249 Jan 03 '18 at 12:39
  • My code is just an example that show how it works, you must pass a string, passing `'custom_block'` will result `custom_block` itself. – DigitCart Jan 03 '18 at 14:17
  • I have find perfect solution with this code. `$data['custom_block'] = html_entity_decode($data['custom_block'][$this->config->get('config_language_id')]['description'], ENT_QUOTES, 'UTF-8');` – user8302249 Jan 05 '18 at 10:21
1

I think you should do something like this

{{custom_block.lang.description | convert_encoding('UTF-8', 'HTML-ENTITIES')}}

You can also try @Digicart suggestion

Ezekiel
  • 671
  • 5
  • 13
  • I have try your way. but it is not work. please check again my question. I have again specify in detail with my code. Thanks. – user8302249 Jan 03 '18 at 12:48
  • Is config_language_id same as language.language_id? Also confirm you have the php extension mbstring and iconv installed to work with php – Ezekiel Jan 03 '18 at 13:18
  • Normally my code is working fine. if, I have add any text or images. it does work. just issue for special character. Thanks. – user8302249 Jan 03 '18 at 13:39
  • Yea i get, I meant to use the convert_encoding you need mbstring and iconv installed – Ezekiel Jan 03 '18 at 15:07