More in this section

Forums / General Discussions / JavaScript Usage and folder structure

JavaScript Usage and folder structure

2 posts, 0 answered
  1. Jesse
    Jesse avatar
    31 posts
    08 Nov 2010
    10 Dec 2010
    Link to this post
    Hey guys,

    I'm converting a site onto the Sitefinity 4.0 platform and I've had some problems. I have some JavaScript that exist on the .masterpage that exist on the page that did a swap image on mouse over. But when I uploaded the .masterpage it wasn't being recognized. Is it that I can't leave JavaScript on my .masterpage and I must use the JavaScript Widget? Part of my next problem is that the file path of those images which would have been in the html on the .masterpage, would now have to be corrected according to the new folder structure. So now that my master would be in "App_Data\Sitefinity\Website Templates\MySite\my.master" I now have to go through the entire page to switch each file path to find the that of the new structure. Hope I'm not confusing anyone.

    The other thing is where in the folder structure would I put the .js files. I realize in the documentation it wasn't too clear on where the files themselves are too go. Is it that all external files must exist within the App_Data folder or can I leave it, lets say at the top level like this "App_Data\Sitefinity\JavaScript\my.js".

    Thanks and looking forward to possible solution.
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    01 Feb 2016
    11 Dec 2010
    Link to this post
    Hi Jesse,

    Thank you for contacting us.

    The problem with the java script file referencing is partly related to how the references should be done - you should either use rooted paths (starting from the site's root) or use one of our built in controls for referencing java script (such as the one in this thread). You can choose any location for your scripts. There is only one thing to not however if you decide to use the ~/App_Data folder. Please note that since .NET treats this folder as protected you cannot directly link to files under this folder. What you have to do is to register a theme, e.g. (~/App_Data/Sitefinity/WebsiteTemplates/Hospital/App_Themes/Green/) and in this theme create a child folder called Scirpts, and put your js there. Sitefinity will automatically create a handle for this path and you will be able to reference scripts in this folder using ~/Sitefinity/WebsiteTemplates/Hospital/App_Themes/Green/Scritps/<scriptFileName>.js. Example bellow:

    <sf:JavaScriptEmbedControl runat="server" ID="jsFile" ScriptEmbedPosition="Head" Url="~/Sitefinity/WebsiteTemplates/Hospital/App_Themes/Green/Scritps/<scriptFileName>.js"></sf:JavaScriptEmbedControl>

    Kind regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered