Using Sightly with javascript json object | Community
Skip to main content
Hemant_arora
New Participant
April 7, 2016
Solved

Using Sightly with javascript json object

  • April 7, 2016
  • 2 replies
  • 3445 views

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.
Best answer by Hemant_arora

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

Hemant_arora
Hemant_aroraAuthorAccepted solution
New Participant
April 20, 2016

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.

edubey
New Participant
April 7, 2016

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