Foren

Image Gallery in Web Content: Small images not displayed

thumbnail
Florian A., geändert vor 12 Jahren.

Image Gallery in Web Content: Small images not displayed

New Member Beiträge: 7 Beitrittsdatum: 19.05.11 Neueste Beiträge
Hey there,

I'm trying to use image gallery thumbnails in my Velocity template. I'm using this code I've found in the Liferay Wiki, however the thumbnails are not displayed. I've set the config option "ig.image.thumbnail.max.dimension=150" in the portal-ext.properties file as one should not change the portal.properties file (I don't know where to find it anyway).

This is my Velocity template code:

#set ($ImageLocalService = $serviceLocator.findService("com.liferay.portlet.imagegallery.service.ImageLocal­ServiceUtil"))
#set ($IGImageLocalService = $serviceLocator.findService("com.liferay.portlet.imagegallery.service.IGImageLoc­alServiceUtil"))

#foreach ($image in $images.getSiblings())

	#set ($url = $getterUtil.getString($image.data))
	#set ($uuid = $getterUtil.getString($httpUtil.getParameter($url, "uuid", false)))
	#set ($groupId = $getterUtil.getLong($httpUtil.getParameter($url, "groupId", false)))
	#set ($imageObj = $IGImageLocalService.getImageByUuidAndGroupId($uuid, $groupId))
	#set ($smallImageId = $imageObj.getSmallImageId())
	#set ($thumbObj = $ImageLocalService.getImage($smallImageId))

	<pre>
	url           = $url
	uuid          = $uuid
	groupId       = $groupId
	imageObj      = $imageObj
	smallImageId  = $smallImageId
	thumbObj      = $thumbObj
	</pre>

	<a href="$image.data" rel="lightbox">
		<img src="/image/image_gallery?img_id=$smallImageId" width="$thumbObj.getWidth()" height="$thumbObj.getHeight()">
	</a>

#end


This is what the portlet output looks like:



The properties for the IMG tag source code are not set correctly:

<img src="/image/image_gallery?img_id=$smallImageId" width="$thumbObj.getWidth()" height="$thumbObj.getHeight()" id="aui_3_2_0_11398">


As you can see, the $imageObj variable has no valid object instance... So I figure I did not set things properly? However, I can't find my mistake, nor any proper documentation...

Where am I wrong?

Cheers!

Florian
thumbnail
Florian A., geändert vor 12 Jahren.

RE: Image Gallery in Web Content: Small images not displayed

New Member Beiträge: 7 Beitrittsdatum: 19.05.11 Neueste Beiträge
So it seams nobody can or wants to help me with this one. Sometimes I really wonder how Liferay made it into Gartner's Magic Quadrant...

What I've found out so far is this:

In the Velocity template, these changes have been made:

#set ($IGImageLocalService = $serviceLocator.findService("[b]com.liferay.portlet.imagegallery.service.IGImageLocalService[/b]"))


Furthermore I've found this wiki article about accessing Liferay services in Velocity templates. In there you can find this tiny little article:

ServiceLocator is a feature which unlocks a lot of power. This power can inadvertently fall into the wrong hands if for example Journal Template creation is granted to less trusted users. Therefore to prevent abuse, or simply to protect less aware portal admins, the feature is disabled by default for all Journal VM contexts. To enable it, edit the value of journal.template.velocity.restricted.variables in portal.properties. See Journal Portlet section of the Portal Properties area.


Great, but no info which values are valid in any documentation. I have set it to an empty value like this:

journal.template.velocity.restricted.variables=


After restarting Tomcat I got my thumbnail images displayed, however there is still no info about the thumbnail dimensions available. It seems there was a bean for the "ImageLocalService" interface In Liferay 5.x , however this is not the case for Liferay 6.x. There still is an interface com.liferay.portal.service.ImageLocalServiceUtil but it is not available as a bean in Velocity...

So how can I read the dimensions of an image in a Velocity template using it's ID?
thumbnail
Christian Schulze, geändert vor 12 Jahren.

RE: Image Gallery in Web Content: Small images not displayed

Junior Member Beiträge: 87 Beitrittsdatum: 19.11.09 Neueste Beiträge
Hello, I has the same Problem like you and I use your Template but modify it, so now it works fine for me.


#set ($ImageLocalService = $serviceLocator.findService("com.liferay.portal.service.ImageLocalService"))
#set ($IGImageLocalService = $serviceLocator.findService("com.liferay.portlet.imagegallery.service.IGImageLocalService"))

#foreach ($item in $image.getSiblings())

    #set ($url = $getterUtil.getString($item.data))
    #set ($uuid = $getterUtil.getString($httpUtil.getParameter($url, "uuid", false)))
    #set ($groupId = $getterUtil.getLong($httpUtil.getParameter($url, "groupId", false)))
    #set ($imageObj = $IGImageLocalService.getImageByUuidAndGroupId($uuid, $groupId))
    #set ($smallImageId = $imageObj.getSmallImageId())
    #set ($thumbObj = $ImageLocalService.getImage($smallImageId))

    <pre>
    url           = $url
    uuid          = $uuid
    groupId       = $groupId
    imageObj      = $imageObj
    smallImageId  = $smallImageId
    thumbObj      = $thumbObj
    </pre>

    <a href="$item.data" rel="lightbox">
        <img src="/image/image_gallery?img_id=$smallImageId" width="$thumbObj.getWidth()" height="$thumbObj.getHeight()">
    </a>

#end


regards
Chris