Wrong charset from view plugins ZF3

     echo $this->headTitle($meta_data->title);
 $this->headMeta()
    ->appendName('description', $meta_data->description);

  $this->headMeta()->setCharset('UTF-8')
     ->appendName('viewport', 'width=device-width, initial-scale=1.0')
     ->appendName('x-ua-compatible', 'ie=edge');
  echo $this->headMeta();

And as result of head view helper I see some wrong charset. Have you some idias, how it can be fixed?
http://joxi.ru/L21RvDNhRV0lRA

1 Like

This has nothing to do with the character set but all HTML attributes are escaped.

You can disable the auto escaping for the view helper: https://docs.zendframework.com/zend-view/helpers/head-meta/#autoescape

Some background information for the topic escaping can be found in the documentation of zend-escaper: https://docs.zendframework.com/zend-escaper/intro/

1 Like

Thank you! But I was seen it in documentation. But it’s not working for me. I was trying:

     $this->headMeta()->setAutoEscape(false)
        ->appendName('description', $meta_data->description);

No result. I have same problem in plugins headScript and headLink:
http://joxi.ru/ZrJpN7bSweQwO2

Maybe ZF have some more global config parameter for escaping?

You must use the latest version of zend-view:

Thank you very much, it was my other mistake, not version.

$this->headMeta()->setAutoEscape(false)
… is working!
But how about over view helpers?: headScript() and headLink() ? It is not a big problem, all scropts and links working. Is it better to use autoescaping? I need to set autoescape option to false for each other by some specific method? Have I some other way?

Yes. (all informations to this topic can be found in the documentation of zend-escaper; see link above)
If you set the meta tag for the Internet Explorer with X-UA-Compatible then you must set the autoescaping to false.

1 Like

Ok, thank you, I undrstood it.

Hello!

Do you know if escaping affects SEO tags? E.g: opengraph image:
<meta property="og&#x3A;image" content="http&#x3A;&#x2F;&#x2F;nisuta.com&#x2F;files&#x2F;products&#x2F;grandes&#x2F;NSAC14.jpg">

instead of:
<meta property="og:image" content="http://nisuta.com/files/products/grandes/NSAC14.jpg">

No, there is no impact on parsing escaped characters in documents. Even better it is the recommended way.
@see Using character escapes in markup and CSS

You can test it with the different tools like the Sharing Debugger: