Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Pieter Haro
Image path in Javascript
September 6, 2011 2:06 AM
Answer

Pieter Haro

Rank: New Member

Posts: 8

Join Date: July 18, 2011

Recent Posts

how to specify the image path in Javascript from Liferay

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


Advait Trivedi
RE: Image path in Javascript
September 6, 2011 4:27 AM
Answer

Advait Trivedi

Rank: Junior Member

Posts: 56

Join Date: March 30, 2010

Recent Posts

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
Samir Gami
RE: Image path in Javascript
September 6, 2011 4:39 AM
Answer

Samir Gami

Rank: Regular Member

Posts: 162

Join Date: February 3, 2011

Recent Posts

Pieter,

You can use absolute path with the javaScript, like
"/Test-portlet/img/myImage.jpg" [ /{Portlet-Name}/img/{imageName} ]
Amos Fong
RE: Image path in Javascript
September 6, 2011 8:15 PM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1898

Join Date: October 7, 2008

Recent Posts

I think you can use the themeDisplay javascript object:

themeDisplay.getPathThemeImages()

Should return something like:
/test-theme/images
Rupesh Chotai
RE: Image path in Javascript
December 6, 2012 10:59 AM
Answer

Rupesh Chotai

Rank: Regular Member

Posts: 163

Join Date: March 23, 2011

Recent Posts

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.