+1-888-365-2779
Try Now
More in this section

Forums / Designing & Styling / App_Themes/<CustomTheme>/Global/ Relative Please

App_Themes/&lt;CustomTheme&gt;/Global/ Relative Please

5 posts, 0 answered
  1. Jaime Weise
    Jaime Weise avatar
    120 posts
    Registered:
    02 Nov 2008
    12 May 2011
    Link to this post
    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? 
  2. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    13 May 2011
    Link to this post
    Can you elaborate a bit more?...what is it you're trying to achieve?
  3. Jaime Weise
    Jaime Weise avatar
    120 posts
    Registered:
    02 Nov 2008
    13 May 2011
    Link to this post
    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. 
  4. Jaime Weise
    Jaime Weise avatar
    120 posts
    Registered:
    02 Nov 2008
    13 May 2011
    Link to this post
    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>

    Register the module here:

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

    Create your rules:

        <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>
     
    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.
  5. Lyubomir Dokov
    Lyubomir Dokov avatar
    43 posts
    Registered:
    01 Nov 2016
    31 May 2011
    Link to this post

    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
5 posts, 0 answered