How can I add extra info like lang="ar" dir="rtl" to the <html> tag like the following?

<html{{ html_attributes }} lang="ar" dir="rtl">

You can use the following code, even though for those specific values, I would find a different way (e.g. setting the language for the shown page).

{% html_attributes.setAttribute("lang", "ar") %}
{% html_attributes.setAttribute("dir", "rtl") %}
<html{{ html_attributes }}>

Inside hook_preprocess_html(), since $variables['html_attributes'] is an Attribute object, so you can use Attribute::setAttribute().

$variables['html_attributes']->setAttribute("lang", "ar");
$variables['html_attributes']->setAttribute("dir", "rtl");
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy