We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8168
    • 1,118 Posts
    I am running 0.9.6.3 and trying to reload my page with an alternate template page using an a href button link code is below:

    <a href="[~[*id*]~]&template=homepage">link</a>


    This is basically attempting to reload the current page with a new template called "homepage"


    Currently this does nothing....

    Any ideas?


    Cheers
      • 8168
      • 1,118 Posts
      Scratch this - it works a dream config file was wrong in the plugin.... ;]

        • 8168
        • 1,118 Posts
        One quick thing, Is it possible to call into the "template=exampletemplate" where exampletemplate is noted the pageLink details? i.e. [*pagelink*] I want to have something dynamic so that as my site has unique templates per page which are named the same as the pagelink title (i am using SEO friendly URLs). so basically i would want this:

        <a href="[~[*id*]~]&template=[*pagelink*]">link</a>



        Is this possible?
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          What do you mean by [*pagelink*]? Is this a TV? Do you mean [*pagetitle*] or [*alias*] or [*menutitle*]?

          It would be very simple to modify the plugin to use one of those instead of having the template specified in the URL.
            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
            • 8168
            • 1,118 Posts
            is [*alias*] the SEO friendly name given to the page? If so that’s the one I am after!
              • 8168
              • 1,118 Posts
              [*alias*] works a dream - thanks!
                • 8168
                • 1,118 Posts
                Is there anyway to perform a check what page you are viewing and then load a designated template?

                i.e.

                if [*alias*] == "chickens" then load template == "chickens"



                Cheers
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Just change how the plugin gets the template name. No need for the ?template=... in the URL in this case. I’ve simply commented out the GET and COOKIE methods and added a line to get the document’s alias.
                  if(!strstr($modx->documentContent, "donotswitch")) { // this page is not switchable
                  /**
                      if (isset($_GET['template'])) {
                          $overrideTemplate = $_GET['template'];
                      } else if (isset($_COOKIE['template']) && $usecookie == 'yes') {
                          $overrideTemplate = $_COOKIE['template']; 
                      } 
                  **/
                      $overrideTemplate = $modx->documentObject['alias'];
                      if (isset($overrideTemplate)) {
                        $table = $modx->getFullTableName("site_templates");
                        $result = $modx->db->select("id, content",$table,"templatename = '".$overrideTemplate."'");
                        if($modx->db->getRecordCount($result) == 1) {
                          $row = $modx->db->getRow($result);
                          $modx->documentObject['template']=$row['id'];
                          $modx->documentContent = $row['content'];
                        } else {
                          $this->messageQuit("Error retrieving template.");
                        }
                        if($usecookie == 'yes') {
                          setcookie("template",$overrideTemplate,time()+604800, "/", "", 0);
                        }
                      }
                  } // end if page is switchable
                  
                    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
                    • 8168
                    • 1,118 Posts
                    Thanks Susan,

                    So what is that section of code actually doing? I dont know any PHP so cant really tell....

                    I am using the mobile detect script to check whether the user is viewing on a mobile initially and automatically switching the template that clads the page on load, then I have an optout button for users that want to view the full version of the site even if they are deemed to be on a mobile device.

                    I have some pages in the site which use templates which are not the same name as their alias so i cant use this line of code on all pages:

                    <a href="[~[*id*]~]&template=[*alias*]">link</a>


                    I need some way of saying on the a href if you are viewing page A then load template Template A etx, if you are viewing page B then load Template A etx...




                    Is that possible?
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      This is sounding more like you just need to assign your pages to the proper templates in the first place. Are the templates really so different? Or is it just a matter of different colors or background images, or different content in the sidebars?

                      When using the plugin, any page you want to assign a template to and not have it change, just put an HTML comment in it somewhere
                      <!-- donotchange -->
                        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