Foros de discusión

Image path in Javascript

Pieter Haro, modificado hace 12 años.

Image path in Javascript

New Member Mensajes: 7 Fecha de incorporación: 19/07/11 Mensajes recientes
how to specify the image path in Javascript from Liferay

abcd.js
var A_TCALDEF = {
	'months' : ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
	'weekdays' : ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
	'yearscroll': true, // show year scroller
	'weekstart': 0, // first day of week: 0-Su or 1-Mo
	'centyear'  : 70, // 2 digit years less than 'centyear' are in 20xx, othewise in 19xx.
	[b]'imgpath' : '../img/'[/b] // directory with calendar images
}


Advait Trivedi, modificado hace 12 años.

RE: Image path in Javascript

Junior Member Mensajes: 56 Fecha de incorporación: 30/03/10 Mensajes recientes
Hi Pieter,

IMHO both the options are OK -

1. an absolute path with theme context "/mytheme/img/myimg.jpg"
2. also a relative path - "../img/myimg.jpg". Note here that path is relative to the JS file.

I am not sure if any one of the above is preferred by Liferay gurus.

Best,
Advait
thumbnail
Samir Gami, modificado hace 12 años.

RE: Image path in Javascript

Regular Member Mensajes: 162 Fecha de incorporación: 4/02/11 Mensajes recientes
Pieter,

You can use absolute path with the javaScript, like
"/Test-portlet/img/myImage.jpg" [ /{Portlet-Name}/img/{imageName} ]
Rupesh Chotai, modificado hace 11 años.

RE: Image path in Javascript

Regular Member Mensajes: 163 Fecha de incorporación: 23/03/11 Mensajes recientes
Hi Samir,
I was looking for the same issue where I have to get the image path in js file and your suggestion worked.
Thanks.
thumbnail
Amos Fong, modificado hace 12 años.

RE: Image path in Javascript

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
I think you can use the themeDisplay javascript object:

themeDisplay.getPathThemeImages()

Should return something like:
/test-theme/images