简体   繁体   中英

How to build a portlet specific conditional in liferay

Our team built a custom portlet to load Google markers onto a map. The markers are created in the template script. We now would like to display these markers in another asset publisher in a list like format. Is there anyway to pass a conditional to the template file depending on the portlet that is requesting it? Or alternatively are there any good methods for building this code into the jsp rather than the template file?

//code that creates the markers on the full map
gmarker=new google.maps.Marker({position:new google.maps.LatLng("$Lattitude.getData()","$Longitude.getData()"),title:"$reserved-article-title.getData()",icon:gicon,map:map});
if(window.location.href.indexOf("fullmap") > -1) {
     google.maps.event.addListener(gmarker, 'click', function() {
         new google.maps.InfoWindow({content:
           '<div id="node_content">
               <div id="siteNotice"></div>
               <h3 id="firstHeading" class="firstHeading">$reserved-article-title.getData(), $City.getData(), $Country.getData()</h3>
               <hr class="m_spacer"/>
               <div id="bodyContent">
                  <p class="gdes">$Description.getData()</p>
                  <img class="m_image" src="$Image.getData()"/>
               </div>
             </div>'
         }).open(map,this);
     });
 }
gmarker.setMap(map);
//redirect code that opens the infowindow on load if the id paramater is not null
if(flag==true){new google.maps.InfoWindow({content:
   '<div id="node_content" class="gs2">
         <div id="siteNotice"></div>
         <h3 id="firstHeading" class="firstHeading">$reserved-article-title.getData(), $City.getData(), $Country.getData()</h3>
         <hr class="m_spacer"/>
         <div id="bodyContent">
            <p class="gdes">$Description.getData()</p>
            <img class="m_image" src="$Image.getData()"/>
         </div>
    </div>'}).open(map,gmarker);
    flag=false;
}

It is liferay 6.1 so we don't get to enjoy the luxuries of the latest release. Here is a screen shot of the two portlets and what they are displaying as well as an example of what we are aiming for. A website that is very similar to what we are attempting can be found here . Were hoping for conceptual ideas on how to differentiate the portlets not code necessarily. Your help is very much appreciated.

If you want to use the same JavaScript function from diverse portlets, then the better way is to put the JavaScript function to the Theme

http://www.liferay.com/documentation/liferay-portal/6.2/development/-/ai/creating-themes-and-layout-templates-liferay-portal-6-2-dev-guide-09-en

and call the function from the portlet-jsp with different properties.

I am not sure if I understood your question correctly, but have you considered creating a custom Display Style for your asset publisher to achieve this? If not, check this out: http://www.rotterdam-cs.com/blogs/-/blogs/hooking-the-asset-publisher-for-custom-display-styles

You can create a new display style with your Map on top and the list below, everything in one jsp (unless you break it down off-course). I think it will possibly resolve your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM