We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13077
    • 15 Posts
    Hello people, I hope you are all well.

    I have a Modx site at the moment and have a template that I use for all my pages. My question is I have been looking at adding my site to Facebook as an app and was wondering if it is possible to make Modx change the default template based on the sub-domain.

    For example:
    Current site: www.mysite.com uses default template to display all info
    Facebook site: facebook.mysite.com uses custom facebook template to display all info
    Mobile site: mobile.mysite.com uses custom template that will display on a mobile phone.

    (That is not my site, didn’t want to put my URL in case in would just result in my been flamed)

    I hope that makes sense, I just wont the same information from my pages but just laid out differently depending on how it’s accessed.

    Thanks
    Ian
      • 13077
      • 15 Posts
      I think I’ve done it.

      I have added to following line to ’document.parser.class.inc.php’ after line 1169 which says ’// get the template and start parsing!’

      if($_SERVER['HTTP_HOST']=='apps.howirritating.com') $this->documentObject['template'] = '7';


      The 7 is the ID of the template I want to use if the URL starts the ’apps’
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        That’s what plugins are for. Instead of hacking the core, make a plugin that does the same thing using the onWebPageInit event.
          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
          • 13077
          • 15 Posts
          Good plan ..... I shall at that to my Todo list now I know how I can change it.

          (I will now google onWebPageInit)
            • 4385
            • 372 Posts

            Plugin Start

            Here is hint from Susan’s template switcher...


            GENERAL:

            $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'];
            }


            CONFIGURATION:

            &overrideTemplate=Template Name;text;Minimal Template



            SYSTEM EVENTS:


            Template Service Events
            OnLoadWebDocument



              DropboxUploader -- Upload files to a Dropbox account.
              DIG -- Dynamic Image Generator
              gus -- Google URL Shortener
              makeQR -- Uses google chart api to make QR codes.
              MODxTweeter -- Update your twitter status on publish.