Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Chris Becker
Accessing theme images in WCM templates
4. April 2013 09:27
Antwort

Chris Becker

Rang: Regular Member

Nachrichten: 110

Eintrittsdatum: 11. Juni 2010

Neue Beiträge

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
Ahmed bouchriha
RE: Accessing theme images in WCM templates
4. April 2013 10:06
Antwort

Ahmed bouchriha

Rang: Junior Member

Nachrichten: 51

Eintrittsdatum: 4. Mai 2012

Neue Beiträge

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.
Chris Becker
RE: Accessing theme images in WCM templates
4. April 2013 13:04
Antwort

Chris Becker

Rang: Regular Member

Nachrichten: 110

Eintrittsdatum: 11. Juni 2010

Neue Beiträge

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
Anonym
RE: Accessing theme images in WCM templates
4. April 2013 13:47
Antwort

Anonym

That is a great piece of code. Good to make note of that.
Chris Becker
RE: Accessing theme images in WCM templates
9. April 2013 08:25
Antwort

Chris Becker

Rang: Regular Member

Nachrichten: 110

Eintrittsdatum: 11. Juni 2010

Neue Beiträge

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
Ahmed bouchriha
RE: Accessing theme images in WCM templates
9. April 2013 09:40
Antwort

Ahmed bouchriha

Rang: Junior Member

Nachrichten: 51

Eintrittsdatum: 4. Mai 2012

Neue Beiträge

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 :

1#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.
Chris Becker
RE: Accessing theme images in WCM templates
9. April 2013 12:26
Antwort

Chris Becker

Rang: Regular Member

Nachrichten: 110

Eintrittsdatum: 11. Juni 2010

Neue Beiträge

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 :

1#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
RE: Accessing theme images in WCM templates
9. April 2013 13:31
Antwort

Henry K

Rang: Junior Member

Nachrichten: 40

Eintrittsdatum: 27. Januar 2010

Neue Beiträge

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