App_Themes/<CustomTheme>/Global/ Relative Please
Make our template lives easier please
Most templates consist of html files filled with root relative references. Then you get the css references that look like:
<link... src="css/some.css" /...
and javascript files like this.
<script... src="js/some.js" /...
Wouldn't it be nice?
If we could just drop the web resources into the global folder of our choice (/CustomTheme/Global/) we could have all our resources found without having to deal with the breaking references or images not being found. You could literally build up a template library by converting a couple html files to .master pages.
Is there a way for this to be done?
I have been looking but not found anything yet. I am going to give iis rewrites a try to see if I can get this scenario to work for me. Another option is to write a custom script to add the resources to a resource library and reference the embedded resources. This seems like a little too much work.
Why can't we just put our js files into the App_Themes folder, too?
This works for css, though not without a couple issues.
Does anyone have a good answer for me?
Can you elaborate a bit more?...what is it you're trying to achieve?
All references from my master pages, my css files, my javascript files should be looking in the ../<Theme>/Global directory when in the format.
src="default.css"
not to be confused with
src="/default.css"
In other words all requests for these files should be relative to my Global folder of my currently selected theme. This would make it super easy to reuse themes.
URL Rewrite did the job just fine.
urlrewriting.com
There is one gotcha that really screwed me up for a bit. That is that if you are following the instructions they tell you to register in the <system.web><httpModules> section. Well, it turns out, for all you people who don't register modules regularly, that modules registered in iis 7x should be registered in the <system.webServer><modules> section. Not both just the <modules> . I have seen some examples that tell you to add both but it is not necessary.
Get the url rewriting module
Register the config section:
<
configSections
>
</
sectionGroup
>
<
section
name
=
"urlrewritingnet"
restartOnExternalChanges
=
"true"
requirePermission
=
"false"
type
=
"UrlRewritingNet.Configuration.UrlRewriteSection,
UrlRewritingNet.UrlRewriter"
/>
</
configSections
>
<
system.webServer
>
<
modules
runAllManagedModulesForAllRequests
=
"true"
>
<
add
name
=
"UrlRewriteModule"
type
=
"UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"
/>
</
modules
>
</
system.webServer
>
<
urlrewritingnet
xmlns
=
"http://www.urlrewriting.net/schemas/config/2006/07"
>
<
rewrites
>
<
add
name
=
"cssRedirect"
virtualUrl
=
".*css/(.*).css$"
destinationUrl
=
"~/App_Themes/NextLevel/Global/css/$1.css"
/>
<
add
name
=
"pngRedirect"
virtualUrl
=
".*img/(.*).png$"
destinationUrl
=
"~/App_Themes/NextLevel/Global/img/$1.png"
/>
<
add
name
=
"jsRedirect"
virtualUrl
=
".*js/(.*).js$"
destinationUrl
=
"~/App_Themes/NextLevel/Global/js/$1.js"
/>
<
add
name
=
"jpgRedirect"
virtualUrl
=
".*img/(.*).jpg$"
destinationUrl
=
"~/App_Themes/NextLevel/Global/img/$1.jpg"
/>
<
add
name
=
"gifRedirect"
virtualUrl
=
".*img/(.*).gif$"
destinationUrl
=
"~/App_Themes/NextLevel/Global/img/$1.gif"
/>
</
rewrites
>
</
urlrewritingnet
>
Hello Jaime Weise,
Thank you for your feedback. I am glad you managed to find a solution for your problem.
However, I am not sure that the scenario you describe is very common. As far as I understood, you want .js files to be included relative to the theme folder? In most cases .js files are not part of your theme, they provide some functionality, that does not change with the theme. So, they should be the same for all themes. Can you give an example of a JavaScript code that needs to be changed with the theme?
As for .css files, all files within the Global folder of your theme are automatically included, as you wrote, so this seems to be fine.
If you really need this functionality, you can always create a custom control that will allow you to specify relative paths and look up those paths relative not to the current folder, but to the folder you want.