We are working on a project where we would like to write a umbraco .net macro that outputs a .js file to be read by another application. Does anyone know how this might be accompolished. Essentially the .js file is a special array of data we need for an external widget - so when admin updates umbraco templates and the macro is run we need a static .js file updates that lives in the /scripts/ folder
Why do you need to generate a physical file for your JavaScript? Why not create something like a HttpHandler which returns the JavaScript and then just have your widget reference the handler.
So you'd just write your JavaScript as a string and put it in a file in the ~/scripts folder (which you can get the file system path by using Server.MapPath). Ensure you take into account file locking, since you could have 2 requests try and write at the same time.
I agree with slace... but instead of using a handler, just use a template containing the needed javascript (references the updated nodes) with references to the content to place in it... then external widget can referece a url using the javascript template.
Umbraco and .js
We are working on a project where we would like to write a umbraco .net macro that outputs a .js file to be read by another application. Does anyone know how this might be accompolished. Essentially the .js file is a special array of data we need for an external widget - so when admin updates umbraco templates and the macro is run we need a static .js file updates that lives in the /scripts/ folder
Thanks
Peter
Why do you need to generate a physical file for your JavaScript? Why not create something like a HttpHandler which returns the JavaScript and then just have your widget reference the handler.
But if you really want to generate a physical file then here's a link on writting files using C# - http://www.csharp-station.com/HowTo/ReadWriteTextFile.aspx
So you'd just write your JavaScript as a string and put it in a file in the ~/scripts folder (which you can get the file system path by using Server.MapPath). Ensure you take into account file locking, since you could have 2 requests try and write at the same time.
I agree with slace... but instead of using a handler, just use a template containing the needed javascript (references the updated nodes) with references to the content to place in it... then external widget can referece a url using the javascript template.
is working on a reply...