You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Peter Sparkes <pe...@didm.co.uk> on 2010/09/28 10:34:31 UTC
Generate javascript dynamically
Hi,
I am using Google maps and have to dynamically insert the parameters for the individual maps into
the javascript. Using xslt I can generate the javascript within <script
type="text/javascript"></script> tags in the html.
However, I wish to insert the javascript using <script src="maps/google.js"
type="text/javascript"></script> and dynamically change the parameters within the google.js file. Is
there any way to make this call invoke the sitemap so that google.js can be generated dynamically.
Thanks
Peter
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
RE: Generate javascript dynamically
Posted by Robby Pelssers <ro...@ciber.com>.
You can easily generate a dynamic javascript file on it's own with flowscript and jxtemplate
function generateGoogleMapsScript() {
//maybe you need some sitemap or request parameters to build the script??
//var sitemapParam1 = cocoon.parameters["sitemapParam1"];
//var requestParam1 = cocoon.request.getParameter("requestParam1");
var sb= new StringBuilder();
//write your dynamic javascript function here
cocoon.sendPage(
"googleMapsJsTemplate",
{
"script": sb.toString()
}
);
}
the script jx-template:
<?xml version="1.0" encoding="UTF-8"?>
<jx:template xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">${script}</jx:template>
Within your xslt you just include a call to a pipeline which will dynamically generate your googlemaps.js file
<script type="text/javascript" src="myblock/googleMaps.js"> </script>
Your sitemap snippets:
<map:match pattern="googleMaps.js">
<map:call function="generateGoogleMapsScript" />
</map:match>
<map:match pattern="googleMapsJsTemplate">
<map:generate src="path/to/googlemapsjxtemplate" type="jx"/>
<map:serialize type="text"/>
</map:match>
Something along these lines should work for you.
Kind regards,
Robby Pelssers
-----Oorspronkelijk bericht-----
Van: Peter Sparkes [mailto:peter@didm.co.uk]
Verzonden: di 28-9-2010 10:34
Aan: Cocoon users
Onderwerp: Generate javascript dynamically
Hi,
I am using Google maps and have to dynamically insert the parameters for the individual maps into
the javascript. Using xslt I can generate the javascript within <script
type="text/javascript"></script> tags in the html.
However, I wish to insert the javascript using <script src="maps/google.js"
type="text/javascript"></script> and dynamically change the parameters within the google.js file. Is
there any way to make this call invoke the sitemap so that google.js can be generated dynamically.
Thanks
Peter
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org