<#assign liferay_ui = taglibLiferayHash["/WEB-INF/tld/liferay-ui.tld"] />
<#assign structureService = serviceLocator.findService('com.liferay.portlet.dynamicdatamapping.service.DDMStructureLocalService') />
<#assign templateService = serviceLocator.findService('com.liferay.portlet.dynamicdatamapping.service.DDMTemplateLocalService') />
<#assign ClassNameLocalServiceUtil = serviceLocator.findService('com.liferay.portal.service.ClassNameLocalService') />

<#assign journalClassNameId = portalUtil.getClassNameId("com.liferay.portlet.journal.model.JournalArticle") />
<#assign newsTemplateId = "" />
<#assign noticeTemplateId = "" />

<div id="myCarousel" class="carousel slide" data-ride="carousel">

     <!-- Wrapper for slides -->
       <div class="carousel-inner">
           
           <#if entries?has_content>
               <#list entries as curEntry>
               
                    <#assign assetRenderer = curEntry.getAssetRenderer() />
                    <#if assetRenderer.getClassName() == "com.liferay.portlet.journal.model.JournalArticle">

                      <#assign article = assetRenderer.getArticle() />
                      <#assign tplKey = article.getTemplateId() >
                      <#assign ddmStructure = structureService.fetchStructure(article.getGroupId(), journalClassNameId, article.getStructureId())/>
                      
                      <#if ddmStructure?has_content >
                          
                          <#if ddmStructure.getName(locale) == "News"  >
                              
                              <#if !newsTemplateId?has_content >
                                  
                                  <#assign templates = templateService.getTemplatesByClassPK(article.getGroupId(), ddmStructure.getStructureId()) />
                                  <#if templates?has_content>
                                    <#list templates as tpl >
                                        <#if tpl.getName(locale) == "News Carousel" >
                                            <#assign newsTemplateId = tpl.templateKey >
                                        </#if>
                                    </#list>
                                  </#if>
                              </#if>
                              <#assign tplKey = newsTemplateId >

                          <#elseif ddmStructure.getName(locale) == "Notice"  >

                            <#if !noticeTemplateId?has_content >
                                  
                                  <#assign templates = templateService.getTemplatesByClassPK(article.getGroupId(), ddmStructure.getStructureId()) />
                                  <#if templates?has_content>
                                    <#list templates as tpl >
                                        <#if tpl.getName(locale) == "Notice Carousel" >
                                            <#assign noticeTemplateId = tpl.templateKey >
                                        </#if>
                                    </#list>
                                  </#if>
                              </#if>
                              <#assign tplKey = noticeTemplateId >

                          </#if>

                      </#if>

                      <@liferay_ui["journal-article"]
                        articleId=article.getArticleId()
                        groupId=article.getGroupId()
                        templateId=tplKey />
                    
                    </#if>
               </#list>
           </#if>
         
       </div>
   <ul class="list-group col-sm-4">
   
   <#if entries?has_content>
    <#assign count = 0>
       <#list entries as curEntry>
        <li data-target="#myCarousel" data-slide-to="${count}" class="list-group-item <#if count == 0>active</#if>"><h4>${curEntry.getTitle(locale)}</h4></li>
           <#assign count = count + 1>
       </#list>
   </#if>
   </ul>

     <!-- Controls -->
     <div class="carousel-controls">
         <a class="left carousel-control" href="#myCarousel" data-slide="prev">
           <span class="fa fa-arrow-left"></span>
         </a>
         <a class="right carousel-control" href="#myCarousel" data-slide="next">
           <span class="fa fa-arrow-right"></span>
         </a>
     </div>

   </div><!-- End Carousel -->