[MGNLDEMO-413] Carousel freemarker syntax failure Created: 03/Feb/23  Updated: 23/Oct/23  Resolved: 18/Aug/23

Status: Closed
Project: Magnolia Demo Projects
Component/s: None
Affects Version/s: None
Fix Version/s: 1.6.9

Type: Bug Priority: Major
Reporter: David Caviedes Marquez Assignee: Anh Vu
Resolution: Fixed Votes: 0
Labels: quickwin
Σ Remaining Estimate: 0d Remaining Estimate: 0d
Σ Time Spent: 1d 6.5h Time Spent: 1d 4.5h
Σ Original Estimate: Not Specified Original Estimate: Not Specified

Sub-Tasks:
Key
Summary
Type
Status
Assignee
MGNLDEMO-416 Implement Sub-task Closed Anh Vu  
MGNLDEMO-417 Review Sub-task Closed Oanh Thai Hoang  
MGNLDEMO-418 piQA Sub-task Closed Oanh Thai Hoang  
MGNLDEMO-419 QA Sub-task Closed Valeria Robles-Garzon  
Template:
Acceptance criteria:
Empty
Task DoD:
[X]* Doc/release notes changes? Comment present?
[X]* Downstream builds green?
[X]* Solution information and context easily available?
[X]* Tests
[X]* FixVersion filled and not yet released
[X]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:
Epic Link: DevX Bucket
Sprint: DevX 44
Story Points: 1
Team: DeveloperX
Work Started:
Approved:
Yes

 Description   

Steps to reproduce

  1. Try to use carousel component template (/travel-demo/templates/components/carousel.ftl) in some demo page

 

Expected results

Carousel shows correctly

Actual results

A freemarker error is produced and component is not rendered

Workaround

Fix Freemarker syntax (5 lines), for example:

Original code: 

dots: ${content.dots!"true"},

 

Fixed code:

dots: ${content.dots?c!"true"}, or dots: ${content.dots?string("true","false")!"true"},

Development notes



 Comments   
Comment by Fabian Mangold [ 26/Jul/23 ]

V&B has just reported that issue as well, when playing around on our public Demo instance.

The first suggested fix (using the "c" builtin is the way to go, given the fact the second approach has been deprecated in newer Freemarker releases).
We may have to update all other boolean params (i.e. arrows, fade, variableWidth, autoplay) as well.

The following snippet should do the trick:

[#-- We only want to render the javascript when not in edit mode --]
[#if !cmsfn.editMode]
<script type="text/javascript">
    $(document).ready(function () {
        $("#" + "${slideShowId}").slick({
            [#if content.slickConfig?has_content]
            ${content.slickConfig?replace("<br/>", " ")}
            [#else]
                dots: ${(content.dots!true)?c},
                arrows: ${(content.arrows!true)?c},
                fade: ${(content.fade!false)?c},
                variableWidth: ${(content.variableWidth!false)?c},
                slidesToShow: ${content.slidesToShow!"2"},
                autoplay: ${(content.autoplay!false)?c},
                autoplaySeconds: ${content.autoplaySeconds!"5"},
                nextArrow: '<button type="button" class="slick-next"><span class="glyphicon glyphicon-chevron-right"></span></button>',
                prevArrow: '<button type="button" class="slick-prev"><span class="glyphicon glyphicon-chevron-left"></span></button>'
            [/#if]
        });
        // Add lazypreload to all lazy images in carousel
        $("#" + "${slideShowId} img.lazyload").addClass("lazypreload");
    });
</script>

Any chance to have this integrated ASAP ?

Thanks,
Fabian

Comment by Anh Vu [ 17/Aug/23 ]

Note: Because currently the 6.3 version does not use magnolia-travel-demo module, this ticket only fix the issue for 6.2 version

Comment by Fabian Mangold [ 17/Aug/23 ]

After a discussion with anh.vu, my fix is actually buggy, as missing values cannot be cast to C. (Doing so will actually throw an NPE and ultimately abort the Freemarker script).
This is explicitly mentioned in the documentation:
https://freemarker.apache.org/docs/ref_builtins_boolean.html

If the value the c built-in is applied on is null/missing, it will stop the template processing with error, just like most other built-ins. If instead you want to output a null literal, see the cn built-in.

So, the right way to go, is:
Null check -> Default value -> Convert to C string,

${(content.dots!true)?c} 

The. code snipped above has been adjusted accordingly.

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