Javascript and Kentico, best friends or fierce enemies?

Shawn Ebeyer asked on November 23, 2015 18:50

Hi there,

I'm trying to include some custom Javascript files as well as jQuery and am having some trouble doing so. Would someone please be able to assist? Can't seem to find any step by steps anywhere. Thanks.


Recent Answers

Joshua Adams answered on November 23, 2015 18:54

What version of kentico are you using? There is a javascript webpart that you can place on the page that you can add and specify the js file that you want to load in. That may be your best bet, but it depends on what version of Kentico you are in. Here is an article that may help otherwise.

0 votesVote for this answer Mark as a Correct answer

Timothy Fenton answered on November 23, 2015 18:59

hello shawn, are you trying to add javascript to the entire site ? If so you could add the javascript in one of two places. First you can add it on the master page on the masterpage tab there is a text box where you can insert includes such as css or javascript, here you can add your include lines for your javascript.

Another place you can add them is on the design page of your master template, you should add a "Javascript" webpart to the master page template and then you can choose a file for it to include and you can even select where to include the javascript file ( head vs top of body vs inline..etc ).

If you are trying to add the javascript to just one page, then the best way is going to be using that same javascript webpart, just add it to the pages layout via the design tab. You configure it with either the script directly in the webpart or a link to the file you want to include. You can even have it automatically generate the script tags if you want to.

One other note on this if you start to see weird issues with the admin UI because your javascripts are interfering with the admin interface, you can add a visibility condition to the javascript webpart. To do this click the > next to the "Visble" property of the webpart and then add the following macro:

{% ViewMode == "LiveSite" %}

and it will only show up on the live site.

Hope this helps

0 votesVote for this answer Mark as a Correct answer

Shawn Ebeyer answered on November 23, 2015 19:31

Thank you Joshua and Timothy. I think I will add a Javascript Webpart and see how it works out

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.