how to reference js and css files

prasanth edvin asked on September 21, 2015 12:09

i have downloaded sample website template it is working correctly in visual studio aspx page but image,script and js is not working while i use that same aspx page template in kentico taking only the data content but not the image slider and java scripts and css styles.

Recent Answers

Maarten van den Hooven answered on September 21, 2015 12:37 (last edited on September 22, 2015 23:12)

Hi Prasanth,

Are you sure you have the images, javascript and CSS in your project? If so look through your browser inspector where the reference is going to so you can debug your problem.

Normally you make an reference to an css like this : <web project>/CMSPages/GetResource.ashx?stylesheetname=MySite see the documentation for more information.

For custom javascripts are normally stored here : ~/CMSScripts/Custom/ but you can also store them on a other location.

You can also read the Tutorial Walkthrough - Creating a new site using ASPX templates for Kentico v7 and here you can find the tutorial for newest Kentico version 8.2.

Good luck with solving the problem, if it is not working please let us known.

If this answer helped you, please vote for my answer :-)

1 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on September 21, 2015 15:51

So it sounds as if you're using ASPX development mode, any particular reason why? I'd suggest using the Portal development mode. It allows you all the same flexibility with less code to write and maintain and take advantage of quite a few more out of the box features. You might also look into using v8.2 vs. v7 as v7 is over 3 years old now and v9 will be coming out in a month or two so save yourself the headache of upgrading later when you can do it now pretty painlessly.

If using Portal mode you can simply place a webpart on a page template and add stylesheets and js file references from within there. Check out this reference on how to setup your folder structure within the physical file system (the majority of this is automatically setup if you use the correct naming conventions within the UI).

If you want to take advantage of the minimization and caching you can use the following lines of code:

Stylesheet in file system: <link href="/CMSPages/GetResource.ashx?stylesheetfile=~/App_Themes/MySiteCodeName/foundation.css" type="text/css" rel="stylesheet"/>

Stylesheet within the UI:
<link href="/CMSPages/GetResource.ashx?stylesheetname=StylesheetCodeName" type="text/css" rel="stylesheet"/>

JS File in the file system (can also be seen in the UI) <script type="text/javascript" src="/CMSPages/GetResource.ashx?scriptfile=/CMSScripts/Custom/MySiteCodeName/jquery.ui.totop.js"></script>

Keep in mind if your site code name is "MySite" and you have physical files within the /App_Themes/MySite directory, by default ASP.NET and IIS will automatically add them to your page, this is standard functionality of an ASP.NET website. If you want more control over them I suggest using the Kentico UI.

2 votesVote for this answer Mark as a Correct answer

Maarten van den Hooven answered on September 21, 2015 16:26

I agree with Brenden about the portal engine is indeed more flexible, easier and more powerful. And again I agree with Brenden to always use the newest Kentico versions. So when it is possible to wait a couple of weeks for Kentico v9 I certainly do that.

More background about the differences : ASPX versus Portal Engine development in Kentico CMS and here an discussion on Stackoverflow about this subject.

If Brenden and I convinced you, here is an tutorial : Walkthrough - Creating a new site using the Portal engine

But of course if there is a reason that you cannot use portal engine and you have questions about your problem in the ASPX template, please let us known so we can help you on the way.

1 votesVote for this answer Mark as a Correct answer

Maarten van den Hooven answered on September 23, 2015 07:48

Hi Prasanth, Did you find an solution and solved your problem?

0 votesVote for this answer Mark as a Correct answer

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