Skip to content
Shannon Deminick edited this page Apr 27, 2015 · 4 revisions

Path Aliases

CDF allows you to have pre-defined paths for your dependencies to reference. This is handy in case you ever change the location of many assets, or if you want to do some kind of theming.

Pre-defined paths

You can pre-define paths during application startup by adding to the PathsCollection

ClientDependency.Core.PathsCollection.AddPath("JQuery", "~/Js/Jquery");

Defining paths in the loader

You can also define path aliases when you render the JS/CSS.

MVC

@Html.RenderJsHere(
    new BasicPath("JQuery", "~/Js/Jquery"),
    new BasicPath("ControlStyles", "~/Css/Controls"))

NOTE: You can add as many paths as you like to the RenderJsHere and RenderCssHere methods.

Webforms

<CD:ClientDependencyLoader runat="server" id="Loader" >
	<Paths>
		<CD:ClientDependencyPath Name="ControlStyles" Path="~/Css/Controls" />
		<CD:ClientDependencyPath Name="JQuery" Path="~/Js/Jquery" />
	</Paths>
</CD:ClientDependencyLoader>

Using Path Aliases

Its super easy to use path aliases, you just need to specify the alias to use when declaring your dependency

MVC

@{
Html.RequiresCss("Content.css", "ControlStyles")
	.RequiresJs("JQuery", "jquery.js");
}

Webforms

<CD:JsInclude runat="server" FilePath="jquery.js" PathNameAlias="JQuery" />
<CD:CssInclude runat="server" FilePath="Content.css" PathNameAlias="ControlStyles" />