eZ Community » Forums » eZ Publish 5 Platform » Links around embedded images produce...

Links around embedded images produce broken HTML

Links around embedded images produce broken HTML

Friday 17 October 2014 3:37:20 pm - 4 replies

In the legacy stack, there was some nice logic in the eZ XML XHTML output handler to inject link parameters into the embed template. This made it so that a link wrapped around an embedded image produced some valid HTML with the <a> tag directly surrounding the image.


 <div class="ezxmltext-field"><div><div class="content-view-embed"><div class="class-image"><div class="attribute-image"><a href="/" target="_self"><img src="/path/to/image.png" width="200" height="86" style="border: 0px solid ;" alt="PNG" title="PNG" /></a></div></div></div></div></div>

Now in the new stack this logic is gone. The output HTML is something like:

 <div class="ezxmltext-field"><p><a href="/" target="_self"><div><div class="content-view-embed"><div class="class-image"><div class="attribute-image"><img src="/var/ezdemo_site/storage/images/media/images/png/316-1-eng-GB/PNG_medium.png" width="200" height="86" style="border: 0px solid ;" alt="PNG" title="PNG" /></div></div></div></div></a></p></div>

I think this is partially because there is no $link_parameters variable available in the image embed template and partially because the XSL just automatically converts a link to an <a> tag directly.

This is bad HTML because there is a <p> tag with nested <div> tags and the <a> tag around all of it. This effectively produces an empty paragraph on some browsers (as the browser tries to parse the bad HTML).

How can we restore the behavior where a linked embedded image wrapped the link directly around the <img> tag?

Modified on Friday 17 October 2014 3:38:13 pm by Peter Keung

Friday 04 September 2015 8:33:23 pm

I tried to solve this for about 3 days now. Last thing was a content view override. Out of ideas.

Modified on Friday 04 September 2015 8:38:44 pm by Johannes Kurz

Friday 04 September 2015 8:37:17 pm

See this issue for more information: https://jira.ez.no/browse/EZP-23513

Friday 04 September 2015 8:43:32 pm

Ok well my image isn't even viewed using ez_render_field (XML Block). eZ Publish 5.3

{{ ez_render_field(newsobject, 'right_text') }}

It seems only a <p></p> tag is generated without a link on the image.
The editing of the xml block is done in the standard legacy backend editor.

Modified on Friday 04 September 2015 8:52:30 pm by Johannes Kurz

Saturday 05 September 2015 10:45:48 pm

Solving my image problem by overriding the non existant base view:

content_view:                         embed-inline:                                    image:                                           template: "Bundle:embed:image.html.twig"                                           match:                                                   Identifier\ContentType: [image]

There you can change the handling of the link.
The parameter may still be missing thought. 

Modified on Saturday 05 September 2015 10:46:36 pm by Johannes Kurz


You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from