App_Themes/<CustomTheme>/Global/ Relative Please - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

App_Themes/<CustomTheme>/Global/ Relative Please

  • 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.


    not to be confused with 


    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. 

    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:

          <section name="urlrewritingnet"
                  requirePermission ="false"

    Register the module here:

    <modules runAllManagedModulesForAllRequests="true">
                 <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />

    Create your rules:

          <add name="cssRedirect"
                destinationUrl="~/App_Themes/NextLevel/Global/css/$1.css" />
          <add name="pngRedirect"
                destinationUrl="~/App_Themes/NextLevel/Global/img/$1.png" />
          <add name="jsRedirect"
                destinationUrl="~/App_Themes/NextLevel/Global/js/$1.js" />
          <add name="jpgRedirect"
                    destinationUrl="~/App_Themes/NextLevel/Global/img/$1.jpg" />
          <add name="gifRedirect"
              destinationUrl="~/App_Themes/NextLevel/Global/img/$1.gif" />
    The only thing that would make this better is if I could have the NextLevel theme somehow be dynamic, but this should do for now. 

    I tried setting this up before and got stymied by the registering change. I hope this helps someone else, too. The only other thing to mention is that I downloaded the source for url rewriter and built it with the .net 4.0 runtime but I don't think that is necessary.
  • 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.

    Kind regards,
    Lyubomir Dokov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items