function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SalesRedSalesRed 

Static Resource > How To Dynamically Bind The Reference Name in VIsualforce Page

Hello,

 

I have static resource in ise in my visualforce pages.  These work well.  To include them I do something similar to the following.

 

<apex:includeScript value="{!URLFOR($Resource.Content_TestSite_HtmlAndScripts, '/scripts/bootstrap-datetimepicker.min.js')}"/>  

 

I wish to change this though to dynamically pass in the resource name that I require.

 

E.g. <apex:includeScript value="{!URLFOR($Resource.{resourceParameterName}, '/scripts/bootstrap-datetimepicker.min.js')}"/>

 

Or <apex:includeScript value="{!URLFOR($Resource.Content_{resourceParameterNa}_HtmlAndScripts, '/scripts/bootstrap-datetimepicker.min.js')}"/>

 

When I try to save this in my IDE I get syntaz errors though.

 

Do you know if what I'm trying to do is possible & if so can both ways I'm trying to set the name above work?

 

Thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 
Rahul SharmaRahul Sharma

Try accessing it like array instead of (.) Dot operator.

example: (Note- resourceParameterName is a variable, not string)

1.
<apex:includeScript value="{!URLFOR($Resource[resourceParameterName], '/scripts/bootstrap-datetimepicker.min.js')}"/>
2.
<apex:includeScript value="{!URLFOR($Resource['Content_'+resourceParameterNa+'_HtmlAndScripts'], '/scripts/bootstrap-datetimepicker.min.js')}"/>

 Hope it helps.

 

 

 

All Answers

Rahul SharmaRahul Sharma

Try accessing it like array instead of (.) Dot operator.

example: (Note- resourceParameterName is a variable, not string)

1.
<apex:includeScript value="{!URLFOR($Resource[resourceParameterName], '/scripts/bootstrap-datetimepicker.min.js')}"/>
2.
<apex:includeScript value="{!URLFOR($Resource['Content_'+resourceParameterNa+'_HtmlAndScripts'], '/scripts/bootstrap-datetimepicker.min.js')}"/>

 Hope it helps.

 

 

 

This was selected as the best answer
SalesRedSalesRed

Thank you.  Works perfectly.

Rahul SharmaRahul Sharma
I just thought to use refer it like an array, I hadn't tested it tough.
Glad it worked. Whew!! :)
VairaVaira
Wow!!!! It works perfectly....
Sukhdeep Singh 1Sukhdeep Singh 1
Hi,
I am getting error at line 2. while at line number 1 file name displays well on VF page
1. Current JS file used - {!pacJSconfigDetails.name}
2. <apex:includeScript value="{!$Resource[{!pacJSconfigDetails.name}]}"/>

Thanks,