留言板

Accessing theme images in WCM templates

thumbnail
Chris Becker,修改在11 年前。

Accessing theme images in WCM templates

Regular Member 帖子: 112 加入日期: 10-6-11 最近的帖子
Hi everyone;

I am using Liferay 6.1 edition in a JBoss app-server environment.

Can anyone tell me how to access images stored in a theme's image folder from within a WCM Velocity template?

I am creating a WCM template that contains a form, and I wish to use an image for the Submit button. I would like to store that button image within the theme, and just reference via a Velocity variable, or at least a Velocity variable that gives me the image directory of the theme and then just append the image name to it.

Any guidance as to how this could be done would be appreciated - thanks in advance!

Regards,

--Chris
thumbnail
Ahmed bouchriha,修改在11 年前。

RE: Accessing theme images in WCM templates (答复)

Junior Member 帖子: 55 加入日期: 12-5-4 最近的帖子
hi Chris Becker :

Try to use :
#set($theme_image_path = $request.get("theme-display").get("path-theme-images"))

for custom themes feel free to visit https://www.themeray.com.
thumbnail
Chris Becker,修改在11 年前。

RE: Accessing theme images in WCM templates

Regular Member 帖子: 112 加入日期: 10-6-11 最近的帖子
Ahmed bouchriha:
hi Chris Becker :

Try to use :
#set($theme_image_path = $request.get("theme-display").get("path-theme-images"))

for custom themes feel free to visit https://www.themeray.com.



Hi Ahmed;

That worked great - thanks for the info!

Regards,

--Chris
thumbnail
Chris Becker,修改在11 年前。

RE: Accessing theme images in WCM templates

Regular Member 帖子: 112 加入日期: 10-6-11 最近的帖子
Chris Becker:
Ahmed bouchriha:
hi Chris Becker :

Try to use :
#set($theme_image_path = $request.get("theme-display").get("path-theme-images"))

for custom themes feel free to visit https://www.themeray.com.



Hi Ahmed;

That worked great - thanks for the info!

Regards,

--Chris


Hey Ahmed;

Any chance you would have a similar approach for getting the path to Javascript files?
I tried using the approach above and just request javascript, as follows:
#set($theme_javascript_path = $request.get("theme-display").get("path-theme-javascript"))

However, this did not work. Any ideas?

Regards,

--Chris
thumbnail
Ahmed bouchriha,修改在11 年前。

RE: Accessing theme images in WCM templates (答复)

Junior Member 帖子: 55 加入日期: 12-5-4 最近的帖子
hello Chris

The theme js path can be retrieved through $themeDisplay.getPathThemeRoot()js on liferay velocity but since $themeDisplay is not available on liferay CMS you cant use it and you have to use the $request.get("theme-display").get("path-theme-images") with some string manipulation like this :

#set($theme_javascript_path = $request.get("theme-display").get("path-theme-images").substring(0, $request.get("theme-display").get("path-theme-images").lastIndexOf("/images")).concat("/js"))


for custom themes feel free to visit https://www.themeray.com.
thumbnail
Chris Becker,修改在11 年前。

RE: Accessing theme images in WCM templates

Regular Member 帖子: 112 加入日期: 10-6-11 最近的帖子
Ahmed bouchriha:
hello Chris

The theme js path can be retrieved through $themeDisplay.getPathThemeRoot()js on liferay velocity but since $themeDisplay is not available on liferay CMS you cant use it and you have to use the $request.get("theme-display").get("path-theme-images") with some string manipulation like this :

#set($theme_javascript_path = $request.get("theme-display").get("path-theme-images").substring(0, $request.get("theme-display").get("path-theme-images").lastIndexOf("/images")).concat("/js"))


for custom themes feel free to visit https://www.themeray.com.


Wow... almost makes you think that Liferay doesn't want this to happen! emoticon


But it works, Ahmed... thanks again for your help!

Regards,

--Chris
Henry K,修改在11 年前。

RE: Accessing theme images in WCM templates

Junior Member 帖子: 40 加入日期: 10-1-27 最近的帖子
Hi--

The real, actual request and themeDisplay objects (not the request and themeDisplay maps) are available in liferay cms (at least in LR 6.1.1)

#set ($serviceContext = $portal.getClass().forName("com.liferay.portal.service.ServiceContextThreadLocal").getServiceContext())
#set ($httpServletRequest = $serviceContext.getRequest())
#set ($objThemeDisplay = $httpServletRequest.getAttribute("THEME_DISPLAY"))

See the 3rd to last comment at http://www.liferay.com/web/raymond.auge/blog/-/blogs/custom-velocity-tools-and-liferay-6-0 . This is really good to know!

--Henry
Bradley Wood,修改在11 年前。

RE: Accessing theme images in WCM templates

thumbnail
Alessandro Lachina,修改在8 年前。

RE: Accessing theme images in WCM templates

New Member 帖子: 24 加入日期: 13-6-12 最近的帖子
I also use it in Freemarker and it work. but in log it give me this error:

Expression request['theme-display'] is undefined on line ......