IN ORCHARD CMS I WANT TO INCLUDE CERTAIN .JS FILES, WHERE SHOULD I PUT THEM AND HOW SHOULD I INCLUDE IT IN MY PROJECT?

Mark Devid

Total Post:102

Points:714
Posted by  Mark Devid
 4942  View(s)
Ratings:
Rate this:
Hi Developers,

In Orchard cms I want to include certain .js files, where should I put them and how should I include it in my project? I am using "TheThemeMachine" as the theme of my project, so I created a folder js and clubed all the .js files require to me in this folder. Now in my Layout.cshtml

I have included in this manner my other .js files But it gives me error in console that

mywebsite/Themes/TheThemeMachine/js/jquery-1.8.0.min.js 404 (Not Found)

Please help,
Thanks in advance. 
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: In Orchard cms I want to include certain .js files, where should i put them and how should i include it in my project?

    Hi Expert,


    To include script files first put you'r script in Scripts directory then simply try following

    Script.Include("jquery-1.8.0.min.js");

    By the way , this is not the correct way of including Jquery library in your theme. Jquery have been registered as a global resource with Orhard.jQuery module thus to include jquery try this :

    Script.Require("jQuery");

    this will ensure that jQuery included only once.but if you insist in putting script files in js directory then you can try this trick.

    Script.Include("../js/yourscript.js");

    don't forget to put a copy of web.config (one exist in Scripts directory) file in your js directory unless you'r script file will never been detected.

    edit :

    making change to ThemeMachine is not a good habit.try creating your own theme based onThemeMachine by orchard command line .this is the way to go :

    codegen theme <theme-name> [/CreateProject:true|false][/IncludeInSolution:true|false][/BasedOn:<theme-name>]  
    for example :

    codegen theme MyTheme /CreateProject:true /IncludeInSolution:true /BasedOn:

    TheThemeMachine orchard command line is an exe file resides in /bin directory. this will create Scripts and Styles directory automatically.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!