Under circumstances where admin pages preview AT markup, the {{ html_element }} variable in some AT core templates may not be defined and result in malformed HTML.

I assume this is because html_element is normally defined in AT_core (\includes\preprocess.inc and/or \includes\misc.inc), and those functions do not run within an administration context.

This would rarely affect a site visitor, but it would be ideal if all AT twig templates using this variable had a default value to prevent this malformed HTML from displaying, regardless of whether the user is on an admin page or not.

Something like:

<{{ html_element|default('div') }}{{ attributes }}>
  {{ content }}
</{{ html_element|default('div') }}>

That said, any solution that prevented malformed HTML from showing up would be great.

Comments

jkovell created an issue. See original summary.

jwkovell’s picture

Attached patch adds a default value to the html_element variable in the following at_core layout_plugin templates.

  • adaptivetheme/at_core/layout_plugin/templates/fourcol/at-layout--fourcol.html.twig
  • adaptivetheme/at_core/layout_plugin/templates/grid/at-layout--grid-2x2.html.twig
  • adaptivetheme/at_core/layout_plugin/templates/grid/at-layout--grid-3x3.html.twig
  • adaptivetheme/at_core/layout_plugin/templates/grid/at-layout--grid-4x4.html.twig
  • adaptivetheme/at_core/layout_plugin/templates/onecol/at-layout--onecol.html.twig
  • adaptivetheme/at_core/layout_plugin/templates/threecol/at-layout--threecol.html.twig
  • adaptivetheme/at_core/layout_plugin/templates/twocol/at-layout--twocol.html.twig

This resolved the issue on our site, but alternative solutions are welcome.

Jeff Burnz’s picture

Priority: Minor » Normal

I don't know how I missed this, quite a while ago I noticed this also and fixed it a similar way:

{%- set element = html_element ?: 'div' -%}
<{{- element }}{{ attributes -}}>
 .....
</{{ element }}>

Probably the default() filter is more elegant actually - nice!

  • Jeff Burnz committed 8ef92ae on 8.x-3.x
    Issue #2882562 by jkovell: Malformed HTML due to undefined variable in...

  • Jeff Burnz committed 8ef92ae on 8.x-2.x
    Issue #2882562 by jkovell: Malformed HTML due to undefined variable in...

  • Jeff Burnz committed 84c1cb7 on 8.x-1.x authored by jkovell
    Issue #2882562 by jkovell: Malformed HTML due to undefined variable in...
Jeff Burnz’s picture

Status: Active » Fixed

Done.

jwkovell’s picture

Excellent. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.