0

Hi I am trying place a dynamic variable in

"{!URLFOR($Resource.ChartsIcons,iconname)}", script in Visualforce page

iconname is variable declared in script but its not taking.

Can anyone tell how to pass dynamic variable in the above.

Basically I wanted to use it in leaflet maps in vf page

L.icon({iconUrl: "{!URLFOR($Resource.ChartsIcons,iconname)}",iconSize: [60, 60] })

Please help.

7
  • Urlfor is resolved during rendering on server side, so, could you please provide more information of what you are trying to do? Aug 20, 2021 at 17:16
  • I want to get the image, so that i can pass it in icon attribute of Leaflet maps leafletjs.com/examples/custom-icons
    – Vivian
    Aug 20, 2021 at 17:18
  • I guess you will have to declare variables for the icons, potentially a map for them, and then use this declared JavaScript map on leaflet with this iconName. Or something around those lines. Aug 20, 2021 at 17:21
  • I have decalred a variable and got the image name but let iconname = 'testimage.png'; L.icon({iconUrl: "{!URLFOR($Resource.ChartsIcons,iconname)}",iconSize: [60, 60] }) thats not working
    – Vivian
    Aug 20, 2021 at 17:28
  • Yes but what I mean is the other way around, eg: let iconOne = "{!URLFOR($Resource.ChartsIcons, 'iconPath')}"; or perhaps a map for these entries. So you can use this on your code such as L.icon({iconUrl: iconOne, iconSize: [60, 60]}). Aug 20, 2021 at 17:39

1 Answer 1

0

Can you try to create an array with each urlfor and use it on your reference to the icon? See below:

Add to your page:

var icons = {
  'icon1': "{!URLFOR($Resource.ChartsIcons, 'icon1')}",
  'icon2': "{!URLFOR($Resource.ChartsIcons, 'icon2')}"
};

...

On your reference you can use the indirection:

L.icon({iconUrl: icons[iconName], iconSize: [60, 60] })

Another option would be to store the path to $Resource.ChartsIcons and then append the path but I feel that this might be more fragile - example.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .