Forums de discussion

getting localized images in asset publisher velocity template

juan meza, modifié il y a 8 années.

getting localized images in asset publisher velocity template

Regular Member Publications: 228 Date d'inscription: 06/01/14 Publications récentes
Hi, I have liferay 6.2 GA4

I have a template for a web content (called news) that i show in an asset publisher, iterating all over the news created...
this works fine... the problem comes when the news has a localized data, (i only manage 3 languages in my site)... then the data comes repeated... in my code i have this:
#if (!$entries.isEmpty())
                    	#foreach ($curEntry in $entries)
                    	    #set( $i = $velocityCount - 1 )
                    		#set($renderer = $curEntry.getAssetRenderer() )
                            #set($className = $renderer.getClassName() )
                            
                            #if( $className == "com.liferay.portlet.journal.model.JournalArticle" )
                                #set( $journalArticle = $renderer.getArticle() )
                                #set( $document = $saxReaderUtil.read($journalArticle.getContent()) )
                                #set( $rootElement = $document.getRootElement() )
                                #set( $xPathSelectorIH = $saxReaderUtil.createXPath("dynamic-element[@name='Image_Header']") )
                                #set( $image_header = $xPathSelectorIH.selectSingleNode($rootElement).getStringValue() )
                    		
                    		#set($bgclass = "bg${i}" )
                    		$xPathSelectorIH.selectSingleNode($rootElement)
							<div class="item bg $bgclass " style="background-image:url( $image_header )"> 
        		     			 <div class="container">
        		        			<div class="carousel-caption">
        		          				<div class=" Dia_links_slider Dia_back_text_slided"> <a href="#"><h1>$curEntry.getTitle($locale)  </h1></a></div>
        		       				</div>
        		    	  		</div>
        		    		</div>
        		    		
        		    		#if( $velocityCount &gt; 4 )
                                #break
                            #end
        		    		
                    		#end
                    	#end
                    #end


as you can see in the code, im refering to the $image_header, if i have a localized news, and have another image for header (or even the same image), the $image_header return the image repeated... for example:
background-image: url(/image/journal/article?img_id=36833&amp;t=1459890307867 /image/journal/article?…36834&amp;t=1459890308128 /image/journal/article?img_id=36835&amp;t=1459890308526 );

it should be:
background-image: url(/image/journal/article?img_id=36833&amp;t=1459890307867 );

depending on the locale selected in the site...

in this example i have 3 langagues for the same news...

i tried passing the $locale to the "getStringValue()" method, but did not work... i checked the api and it does not exist (the getStringValue method with the locale)

so my question is, how can i get the localized image?


thank you!
thumbnail
Yogesh Sharma, modifié il y a 8 années.

RE: getting localized images in asset publisher velocity template (Réponse)

Junior Member Publications: 32 Date d'inscription: 07/03/12 Publications récentes
Juan,

You need to look bit more deeper to get language specific content. Xpath dynamic-element[@name='Image_Header'] gives dynamic element and it have all the available languages inside it. So you need to prepare xpath with language so that you gets the value for exact language.

For example english, try it:
dynamic-element[@name='Image_Header']/dynamic-content[@language-id='en_US']