Skip to main content
Hemant_arora
Level 8
Apr 7, 2016 8:56 AM UTC
Solved

Using Sightly with javascript json object

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. 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Hemant_arora
Hemant_aroraAccepted solution
Level 8
Apr 20, 2016 8:31 AM UTC

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.

2 replies

edubey
Level 10
Apr 7, 2016 10:20 AM UTC

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

Translate
Hemant_arora
Hemant_aroraAuthorAccepted solution
Level 8
Apr 20, 2016 8:31 AM UTC

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.

Translate