This is a migrated thread and some comments may be shown as answers.

Changing the path of the stylesheets

10 Answers 311 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Brendan Vogt
Top achievements
Rank 1
Brendan Vogt asked on 05 Aug 2011, 12:49 PM
Hi,

I am using the latest version of Telerik MVC with my ASP.NET MVC 3 application.  I took what was in contents and put it into another directory under root -> Assets -> telerikaspnetmvc68803.  I don't know where to specify that the path has changed because it is still looking for the controls under ~/Content/...

Do I need to add my stylesheets like this?  Can I just add them like I would normally add them?

@(Html.Telerik().StyleSheetRegistrar()
   .DefaultGroup(group => group
      .Add("telerik.common.min.css")
      .Add("telerik.webblue.min.css")
      //.Combined(true)
      .Compress(true)))

I normally just add it like this:

<link href=".. style goes here.." rel="stylesheet" type="text/css">

If I were to register my javascripts like this then it adds a reference to a jquery file. I don't want this reference to be added because I have a newer version that I want to use. How do I get it to use the newer version?

@(Html.Telerik().ScriptRegistrar()
   .DefaultGroup(group => group
      .Add("telerik.common.min.js")
      .Add("telerik.treeview.min.js")
      .Compress(true)))


Please help :)

Brendan

10 Answers, 1 is accepted

Sort by
0
nachid
Top achievements
Rank 1
answered on 05 Aug 2011, 02:53 PM
Here is how I did it:

WebAssetDefaultSettings
.ScriptFilesPath     = @"~/Assets/Scripts";             
WebAssetDefaultSettings.StyleSheetFilesPath = @"~/Assets/Sheets";
0
Dimo
Telerik team
answered on 05 Aug 2011, 02:59 PM
Hello,

You need to set DefaultPath(), as described in the documentation:

http://www.telerik.com/help/aspnet-mvc/web-assets-working-with-javascript-web-assets.html#ChangeDefaultPath

Note that the setting must come before the Add() statements in the group.

The same page explains how to disable the automatic jQuery registration.

All the best,
Dimo
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

0
Brendan Vogt
Top achievements
Rank 1
answered on 17 Aug 2011, 09:49 AM
Thanks.

I have my own stylesheets and jQuery files in a different location than where my Telerik files are.  When using StyleSheetRegistrar in my scenario, is this the best way to do it?  This is how I did it:

@(Html.Telerik().StyleSheetRegistrar()
   .DefaultGroup(group => group
      .DefaultPath("~/Assets/telerikaspnetmvc/2011.2.712/Content/")
      .Add("telerik.common.css")
      .Add("telerik.webblue.min.css")
      .DefaultPath("~/Assets/Stylesheets/")
      .Add("hef.css")
      .Compress(true)
   )
)

Also when using ScriptRegistrar, is this how it must be done when I want to add my own JavaScript files to the Telerik files?  Do I need to specify the Compress and JQuery properties twice?

@(Html.Telerik().ScriptRegistrar()
   .DefaultGroup(group => group
      .DefaultPath("~/Assets/telerikaspnetmvc/2011.2.712/Scripts/")
      .Compress(true)
   )
   .jQuery(false)
)

@{Html.Telerik().ScriptRegistrar()
   .DefaultGroup(group => group
      .DefaultPath("~/Assets/JavaScripts/jQuery/")
      .Add("jquery-1.6.2.min.js")
      .Compress(true)
   )
   .jQuery(false);
}

0
Dimo
Telerik team
answered on 17 Aug 2011, 10:02 AM
Hi Brendan,

The correct way to achieve your goal is to use additional group(s), not define several paths for the same group. Please refer to the previously provided documentation page.

Regards,
Dimo
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

0
Brendan Vogt
Top achievements
Rank 1
answered on 17 Aug 2011, 10:28 AM

Ok thank I will do just that.  I tried the following as what you suggested but it is not working.  I have the latest jQuery file in its own location.  So I am wanting to load this jQuery file first like:

@(Html.Telerik().ScriptRegistrar()
   .Scripts(scripts => scripts
      .AddGroup("JavaScriptAssetLocation", group => group
         .Add("~/Assets/JavaScripts/jQuery/jquery-1.6.2.min.js")
         .Compress(true)
      )
   )
   .jQuery(false)
)

@(Html.Telerik().ScriptRegistrar()
   .DefaultGroup(group => group
      .DefaultPath("~/Assets/telerikaspnetmvc/2011.2.712/Scripts/")
      .Compress(true)
   )
   .jQuery(false)
)

It gives an error after the first ScriptRegistrar.  It is looking for telerik.common.js.  Error:

Specified file does not exist: "~/Scripts/telerik.common.js".

Please help me construct this correctly.  I even tried swapping around the 2 ScriptRegistrar but it seems like it needs jQuery to be loaded first.

Thanks.

0
Dimo
Telerik team
answered on 17 Aug 2011, 04:08 PM
Hi Brendan,

As suggested by the error, you need to define the DefaultGroup path in the first ScriptRegistrar. Currently I don't see a reason to have two ScriptRegistrars.

Regards,
Dimo
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

0
Brendan Vogt
Top achievements
Rank 1
answered on 18 Aug 2011, 06:54 AM

Hi,

I don't think you are understanding what I am trying to do.

I have my jQuery file in a different directory as to what comes default with Visual Studio.  The reason for this is because I have downloaded the latest version of jQuery jquery-1.6.2.min.js.  I have my Telerik MVC content and scripts directories in a different directory.  As to what I have seen the Telerik scripts needs the jQuery file to be loaded first.  I have deleted the content and scripts directories that come by default with an ASP.NET MVC application.

Telerik scripts directory:
~/Assets/telerikaspnetmvc/2011.2.712/Scripts/

My jQuery directory:
~/Assets/JavaScripts/jQuery/

I changed the ScriptRegistrar (as to your recommendation) to that of below:

@(Html.Telerik().ScriptRegistrar()
   .DefaultGroup(group => group
      .DefaultPath("~/Assets/telerikaspnetmvc/2011.2.712/Scripts/")
      .Compress(true)
   )
   .Scripts(scripts => scripts
      .AddGroup("JavaScriptAssetLocation", group => group
         .DefaultPath("~/Assets/JavaScripts/jQuery/")
         .Add("jquery-1.6.2.min.js")
         .Compress(true)
      )
   )
   .jQuery(false)
)

This gave me an error.  I swapped the 2 around so that it can read jQuery first as such but it still seems to load the default Telerik JavaScript files first.  This is the changed code:

@(Html.Telerik().ScriptRegistrar()
   .Scripts(scripts => scripts
      .AddGroup("JavaScriptAssetLocation", group => group
         .DefaultPath("~/Assets/JavaScripts/jQuery/")
         .Add("jquery-1.6.2.min.js")
         .Compress(true)
      )
   )
   .DefaultGroup(group => group
      .DefaultPath("~/Assets/telerikaspnetmvc/2011.2.712/Scripts/")
      .Compress(true)
   )
   .jQuery(false)
)

What am I doing wrong here?  Please provide code samples as to how it must be done.

0
Dimo
Telerik team
answered on 18 Aug 2011, 08:07 AM
Hello Brendan,

The correct configuration is:

@(Html.Telerik().ScriptRegistrar()
    .Scripts(scr => scr.AddGroup("jq", group => group.Add("~/jquery-location/jquery-1.6.2.min.js")))
    .DefaultGroup(group => group.DefaultPath("~/telerik-scripts-location/"))
    .jQuery(false)
)

However, it turned out that the DefaultGroup scripts are always output first, so you should abandon this approach and register the jQuery script outside (and before) the ScriptRegistrar.

Greetings,
Dimo
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

0
Brendan Vogt
Top achievements
Rank 1
answered on 18 Aug 2011, 09:06 AM
Thanks.  I thought as much.

Just another question. Do I need to specify Compress(true) per group or is once enough? And jQuery(false) needs to be specified where? Only after DefaultGroup? Or anywhere?

0
Dimo
Telerik team
answered on 18 Aug 2011, 09:20 AM
jQuery(false) is needed in all ScriptRegistrar instances.

As seen in the ScriptRegistrar declaration, Compress(true) and Combined(true) are defined per group, so you should set them multiple times, if needed. Note that compression works only if combination is enabled.

Regards,
Dimo
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

Tags
General Discussions
Asked by
Brendan Vogt
Top achievements
Rank 1
Answers by
nachid
Top achievements
Rank 1
Dimo
Telerik team
Brendan Vogt
Top achievements
Rank 1
Share this question
or