Search code examples
javascriptmaster-pagessitefinity

Sitefinity adding javascript to custom master page


I am new to Sitefinity. We are trying to create some custom master pages in which we need to include some javascript files. so we have created a project as below: enter image description here

In the Default.Master we are trying to add .js file as below. But it is not working

<%@ Master Language="C#" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />


    <script src="../Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="~/Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="/Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>

</head>

When I view source of html page it adds the reference as below

 <script src="../jquery-1.9.1.min.js" type="text/javascript"></script>
 <script src="core.min.js" type="text/javascript"></script>
<script src="~/jquery-1.9.1.min.js" type="text/javascript"></script>

But none of that working.

I even put .js files in theme (Global folder) even that is not working.

Cheers


Solution

  • With Sitefinity project, I think you need to follow the structure rule, below is the sample: Sitefinity Project Structure

    After change the Structure, you can load Js or Css in master page like that: Ex 1: load Js

    <script src="/Sitefinity/WebSiteTemplates/SunwayTemplate/JS/modernizr-2.7.1.min.js"></script>
    

    Ex 2:load Css

    <link href="/Sitefinity/WebSiteTemplates/SunwayTemplate/App_Themes/SunwayTheme/Global/style.css" rel="stylesheet">
    

    You can read more information about the Sitefinity Structure in: http://docs.sitefinity.com/website-templates-file-structure