[opencms-dev] How to add a javascript file to the template

Joe Desbonnet jdesbonnet at gmail.com
Mon Sep 12 18:00:17 CEST 2005


You have a few alternatives:

The first is simply to embed the code in the HTML page. Eg:
<script language="Javascript">
my code...
</script>

This is the easiest, but can be wasteful on bandwidth if the code is long.


Next option (which I think it the best): Create a directory in your template 
module directory and put the script there. Eg 
/system/modules/com.myCompany.opencms.templates.mytemplate/javascript/myScript.js

Link it as follows:
<script src="<%=cms.link("/system/modules/com.myCompany.opencms.templates.mytemplate/javacript/myScript.js")%>"
/>

BTW: the 'cms' object is obtained like this:
<%
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, 
response);
%>

Joe


On 9/12/05, pat sad <hlp.psaad at gmail.com> wrote:
> 
> Hy All,
> 
> I want to include a javascript file to my template. Does anyone know
> what to include in the head section of my template ?
> 
> 
> ex: <script src="menu.js"></script>
> 
> Thank you.
> 
> 
> _______________________________________________
> This mail is send to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://mail.opencms.org/mailman/listinfo/opencms-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20050912/f1448bf6/attachment.htm>


More information about the opencms-dev mailing list