[MGNLDEMO-389] Demo: TextImage component does not render/error if Asset-Link is broken Created: 25/Oct/21  Updated: 25/Oct/21

Status: Open
Project: Magnolia Demo Projects
Component/s: None
Affects Version/s: 1.6.3
Fix Version/s: None

Type: Task Priority: Neutral
Reporter: Christian Ringele Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File textImage.ftl    
Template:
Acceptance criteria:
Empty
Task DoR:
Empty

 Description   

Reproduce

  1. Upload a new Asset.
  2. Use this Asset in a textImage component
  3. Publish the page you linked in the component to the asset -> Render the page on the public -> reproduction on public
    OR
    Delete the Asset -> Render the page on the public -> reproduction on Author.

Problem

The textImage component renders a null-pointer error if the is an non-rsolvable asset link.
There is a missing null handling -> "assetLink could not be resolved to an asset via the damfn.

Solution

Use this code:
With a proper null check on the 'rendition' object.

[#if content.image?has_content]
    [#assign rendition = damfn.getRendition(content.image, "original")!]
    [#if rendition?has_content]
        [#assign hasImage = true]
        [#assign divClass = "${divClass} text-image-section"]
        [#assign imageClass = "content-image-${imagePosition}"]
        [#include "/travel-demo/templates/macros/imageResponsive.ftl"]
        [#assign imageHtml][@imageResponsive rendition content imageClass false def.parameters /][/#assign]
    [/#if]
[/#if]

I have attached the whole script file to replace.
textImage.ftl


Generated at Mon Feb 12 05:19:12 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.