We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41375
    • 2 Posts
    Working on a MODx Revo based site and trying to write a simlpe plugin (inspired by 'template switcher plugin written in the past for Evo). Below is the code

    if (isset($_GET['template'])) {
       $template_id=$_GET['template'];
    
       if(isset($template_id)){
           $template = $modx->getObject('modTemplate', $template_id);
           $modx->resource->template = $template->get('id'); 
       }
    
    }


    Eventually the plugin will include much more checks etc, however for now I just want to make sure it works. Idea is simple, it's supposed to get different template for a page based on template param provided with the url. And the problem that prevents it from working as I want it to is modx caching.

    My question is, how can I manipulate cache (clear/reload?) on this particular scenario so the plugin does its job?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You would need to remove this resource's cache file at some point before the cache is checked. If a resource is subject to having its template switched, it shouldn't be cached in the first place. This was always a problem with this template switcher, which was why it was removed from the default Evo installation.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 41375
        • 2 Posts
        is there any way to load same page with two different layouts then?
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          The best way would be to design the template so that the layouts are managed by CSS, and use a snippet to determine which .css file to use.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 4172
            • 5,888 Posts
            you can create a snippet, which loads different chunks, based on url-params.
            For caching the different outputs you can use
            https://github.com/opengeek/getCache
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!