1

I'm looking to call my scripts through an apex:component. So instead of having 3 includes on my page, I want

<c:scripts />   

and the 'scripts' component will contain the following.

<apex:component >       
 <apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/jquery-1.9.1.js')}"/> 
 <apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/jquery-ui-1.10.3.custom.min.js') }" /> 
 <apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/anotherScript.js') }" />        
</apex:component>

But if I only want one of these scripts, can I pass a argument into the component call? Something like the following...

    <c:scripts
      myScript = true />

And then the component...

<apex:component >       
 Boolean myScript = <apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/jquery-1.9.1.js')}"/> 
 <apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/jquery-ui-1.10.3.custom.min.js') }" /> 
 <apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/anotherScript.js') }" />        
</apex:component>

Is there an elegant way of doing this?

Cheers

1 Answer 1

1

Found an answer :)

<apex:component>

    <apex:attribute name="includejQuery" type="Boolean" required="false" default="false" description="True to include jQuery" />

    <apex:outputPanel layout="none" rendered="{!includejQuery}">
        <apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/jquery-1.9.1.js')}"/> 
    </apex:outputPanel>

        <apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/jquery-ui-1.10.3.custom.min.js') }" /> 
        <apex:includeScript value="{!URLFOR($Resource.jQuery, 'jQuery/js/anotherScript.js') }" />

</apex:component>

Then in my page:

<apex:page>
    ...
    <c:Scripts includejQuery="true" />
    ...
</apex:page>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.