Expand my Community achievements bar.

SOLVED

Using Sightly with javascript json object

Avatar

Level 8

Hi

I am trying to convert an existing component jsp to sightly html.

The jsp has the following code:

<script>

            var MY_CAROUSEL_PARAMS_A = {
                control:                        {

                                                            controls:        ${properties.controlsType eq 'controls' ? 'true' : 'false'}
                                                                <c:if test="${properties.controlsType eq 'pager' || properties.controlsType eq 'both'}" >,

                    pager:        {

                        center: ${properties.centerNav eq 'true' ? '1' : '0'},
                        buildPager:        function(pageIndex){

                            var hoverImage = '';

                            var hoverText = '';

                            var hoverWidth = '';

                            switch(pageIndex){
                               <c:forEach var="slide" varStatus="loop" items="${carouselSlides}">
                                    case ${loop.index}:
                                    hoverImage = '${slide.value.tooltipImgPath}';
                                    hoverText = '${slide.value.tooltipText}';
                                    hoverWidth = '${slide.value.tooltipWidth}';
                                    break;
                                </c:forEach>
                            }

                        }

                    }

                          </c:if>                                },

</script>

I am able to get most of the values using sightly inside the script tag.

But how do I implement the <c:if> or <c:foreach> tags in sightly inside a script tag for the above code in bold font. 

1 Accepted Solution

Avatar

Correct answer by
Level 8

Thanks edubey.

I could not find any help in the above documentation. However I followed a different approach and did some java code to get the loop working.

View solution in original post

2 Replies

Avatar

Level 10

Sightly provides similar for loop which can be used.

1. You can either use data-sly-list provided by sightly, Documentation

2.Or put you business logic for JSON in javascript use api file. You will have access to all data and api you need to generate json ( Should be easy to use and maintain but hard to debug) Article: http://adobeaemclub.com/javascript-use-api-with-a-simple-component-in-sightly/

Thanks

Avatar

Correct answer by
Level 8

Thanks edubey.

I could not find any help in the above documentation. However I followed a different approach and did some java code to get the loop working.