We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1841
    • 141 Posts
    I have been trying to create a mobile version of my website and at first I used the mod mobile plugin along with Jquery mobile to create a different template layout for standard and mobile versions.

    This worked a treat except for the big stumbling block that means as soon a resource is cached the template is stuck on whatever version was loaded. This of course is not ideal, nor is the only solution which would mean having everything uncached.

    So I've since been looking at sending mobile users to a m. sub-domain which would either have another instance of modx or be another context. Now ideally I'd just like to use a context however I really do need to have different templates for the standard and mobile versions BUT I'd rather avoid having to create 2 versions of a resource whenever I create one (I create at least 7-8 pages a week).

    Now I understand that if I created an extra context for the mobile subdomain I could still load resources from the "web" context however I am assuming that this will simply load that resource with the default "web" template. Is there a way to over-ride this and load those resources with a different template (ie a mobile version) is called from the mobile context?

    If not is there an easy way to share the resources table with 2 different modx installs or is there an easier way I'm not thinking of?
      • 3749
      • 24,544 Posts
      I would not use contexts or a separate install for this. I'm sure there's a way to make it work. The simplest solution in the short term, would be to clear the cacheable checkbox and make all pages non-cacheable. Obviously that's not ideal.

      I don't use that system, but it's likely that what you need is to make whatever tag triggers the template change non-cached. You can call any tag uncached in Revolution by putting an exclamation point after the two opening brackets:

      [[!snippetName]]
      [[!$chunkName]]
      [[!*TvName]]
      [[!+placeHolderName]]
      [[!++SystemSettingName]]
      



      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 39932
        • 483 Posts
        Referencing your Title (without consideration of the content):

        A Context is basically a location of the website under which different running configuration may be set. The three most common examples of this are other domains, subdomains and localization. There are many other uses for Contexts, but YMMV on how effective they are. On my website, I use Contexts as both subdomains and divisions of document types.

        Regarding your Specific Questions

        This worked a treat except ... as soon a resource is cached the template is stuck on whatever version was loaded.

        This is an issue that I have been working on pretty extensively, and I have found a partial solution. I made a Template Switching plugin utilizing both OnLoadWebDocument, and OnWebLoadCache. This works pretty darned well, even on Cached pages. (I've not written the tutorial yet as there are still a few bugs).

        So I've since been looking at sending mobile users to a m. sub-domain...

        Sounds reasonable.

        Now ideally I'd just like to use a context...

        That's part of what Contexts are for.

        I really do need to have different templates for the standard and mobile versions...

        That's what Templates are for too... So far, all of your reasoning is sound.

        I'd rather avoid having to create 2 versions of a resource...

        Good. This duplication can create loads of problems for maintenance. Modularity is key to simple maintenance.

        Now I understand that if I created an extra context for the mobile subdomain I could still load resources from the "web" context however I am assuming that this will simply load that resource with the default "web" template...

        If you load the resource that way, yes, you are correct.

        Is there a way to over-ride this and load those resources with a different template (ie a mobile version) is called from the mobile context?

        Yes, you may. There are a number of ways, quite easily. As you indicated before, you could do this by creating multiple resources, but this is not desirable for you (and given you development cycle, I would agree). You could also use a Template Switcher like my plugin, that is triggered when specific conditions are met.

        This may also be done by having a Subdomain Context with one page only, gains its content from the matching URL on the "web" context. In this case, it would have its own Template and use a single Snippet call.

        Alternatively, (which I think is ideal), you could make a "Template Action" that is triggered when you ask for a URL + '/mobile/'. This would have it's own Template, but could utilize the Content of the "Parent" resource. Setting this up is extremely easy. The best part about this solution is that it neither requires a new Context, nor duplication of Content.

        All 3 solutions seem viable for you. Each has their own considerations, however. If you need more details, let me know (post, message or e-mail). I have working demos of all of the methods above. [ed. note: fuzzicallogic last edited this post 11 years, 8 months ago.]
          Website: Extended Dialog Development Blog: on Extended Dialog
          Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
          Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

          Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".
          • 1841
          • 141 Posts
          Hi Fuzzicallogic, Thank you for the quick and detailed reply, it really is appreciated.

          Ideally I'd love to load the same pages rather than use a sub-domain or duplicate the content, the template action sounds very interesting but I wouldn't have any idea how you'd go about doing such a thing.

          One thing to consider is that I am using the supercache plugin as I've found it really does speed things up but I don't know if that has any impact on the options you've suggested.

          I'd love to hear more about the template action.

          Thanks again smiley
            • 1841
            • 141 Posts
            Thank you also Bob, as ever you do provide a voice of reason. I can't however have the site uncached as it would just die, I really rely on caching to make sure it's fast and copes with surges in traffic.

            The system uses a tag within the same template to differentiate the mobile and standard versions and no matter what I've tried I can't get the caching to work with this, although this could be complicated by the supercache plugin.

            ideally I'd rather hold off using this uncached and wait till I have a more permanent solution.
              • 3749
              • 24,544 Posts
              You might try disabling the SuperCache plugin and see if that makes a difference. BTW, fuzzicalogic has done a lot more work with template switching than I have. His third option sounds like it might be a good solution.


              ------------------------------------------------------------------------------------------
              PLEASE, PLEASE specify the version of MODX you are using.
              MODX info for everyone: http://bobsguides.com/modx.html
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 1841
                • 141 Posts
                Hi Bob,

                Thanks for the reply, I did try disabling the supercache at one point but still couldn't get it to work. The third option sounds great, would this work with mobile detection via htaccess?

                  • 39932
                  • 483 Posts
                  @antsplace:

                  I wouldn't have any idea how you'd go about doing such a thing...

                  That's ok. Most of the code needed for my solutions are already on the forums.

                  One thing to consider is that I am using the supercache plugin...

                  I don't think that this affects anything. Generally this is the least fickle of the Template/OnPageNotFound Plugins that I have written. It doesn't require any funny cache tricks, is compatible. This is how it works:

                  Synopisis

                  You make a Template called Alias (Template). It adds a "sub-page"/extra path segment to every document of a given Template that it is a child of. An Example: If you make a Resource of the Alias Template named "edit-form" and make it a child of any single Resource of the Argyle Template, All Argyle Resources will have the extra URL path "/edit-form".

                  The way you would use it is you would make a Resource, give it the Template "Alias (Template)", name it "mobile" and place a copy under one of every type of page that you need to be mobile. From there, you just make a single snippet that grabs the content from its "parent" (notice the quotes). I know that many are not necessarily code-oriented like me, so I do help with this. if necessary. It is mych easier to demonstrate than to explain. Hopefully, this makes sense so far?

                  The down-side (based on your need) to this plugin is that it will not apply to every page, just every page of any template that you place one under. If you have a lot of templates that all need the same functionality, then this isn't the best solution. Also, the "mobile" resource would be "hybrid"-cached. That is, it would use cached content, but it itself would query everytime. The load is typically negligible, however, and you would not have to worry about diluting search results. The real question is going to be, how many Templates do you have? If you have more than 1, then this solution is still useful (often incredibly), but it will need to be tweaked. If there is just the 1, it will accomodate you perfectly.

                  The up-side is that it uses very little processing to accomplish what you need, even if you have 50 Templates. Another upside (based on my needs) is that it allows you to have specialized extra functionality for each template. The major consideration for your needs (as you state them) is that it uses one resource, one snippet, and one plugin. No Contexts, no cache tricks, and you may cache everything as normal. Strictly speaking, it is not a Template Switcher, but a Template Complement. The new Template is its own Template and is the new Resource is a "shared" Resource.

                  The plugin is simple. Just grab the code from and follow this tutorial, If you have problems with it, simply let me know. (PS, the tutorial is still a work in progress, so if there is something you don't understand, let me know. The code is quite stable) Also, I do work with people directly over Skype or GTalk (just e-mail me from my profile), the whole process just takes a few minutes (literally). [ed. note: fuzzicallogic last edited this post 11 years, 8 months ago.]
                    Website: Extended Dialog Development Blog: on Extended Dialog
                    Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
                    Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

                    Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".
                  • You don't need to make a separate context and if your using jQuery Mobile it is quite simple.

                    First make your jQuery mobile template with the sections of the website you want to make a mobile version of. then in each section use a getResourceField call or getResources to get the content area of the resources that should display in each section.

                    Then just redirect mobile users to the mobile version no template switching involved.

                    Remember when making a mobile site you should focus on the content especially if its a jQuery Mobile site otherwise I would recommend you use a Responsive design approach.

                    You can see the site I used jQuery Mobile on here:

                    Desktop version: http://pelotonadvantage.com/

                    Mobile version: http://pelotonadvantage.com/mobile

                    I hope that helps.
                      Benjamin Marte
                      Interactive Media Developer
                      Follow Me on Twitter | Visit my site | Learn MODX
                      • 1841
                      • 141 Posts
                      @Fuzzicallogic thank you for the valuable advice, it is very much appreciated. So just to try and get my head round this idea, you would need to create a child resource for every resource you have? or just a child template of every template?

                      The site has 12 templates and a few thousand resources so creating childlren of each would be problematic at best.

                      I'll have a look and see if I can figure it out but may very well call on your assistance.

                      @benmarte If you only have a few pages and 1 template then I would agree this is not a bad approach however anything above this then becomes too problematic and the pages would be far too big. There is also the issue of the great god Google, having one page creates all sorts of duplicate content issues that I wouldn't even want to think about.

                      Having a site with 12 templates and a few thousand pages rules this option out completely. I am already using a responsive design however this isn't ideal, you have to use the same code that's on the page (restrictive) and you cannot use many of the innate abilities of smartphones.
                      [ed. note: antsplace last edited this post 11 years, 8 months ago.]