Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • PETER 2 posts 22 karma points
    Feb 05, 2011 @ 05:19
    PETER
    0

    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

     

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Feb 05, 2011 @ 08:22
    Aaron Powell
    0

    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.

  • Daniel Bardi 927 posts 2562 karma points
    Feb 05, 2011 @ 10:43
    Daniel Bardi
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft