We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21301
    • 93 Posts
    I was looking for a way to apply a different template to a document at runtime. This way I could create a ’print this page’ template without menu’s etc.

    Does anybody know how to do this easily?

    I couldn’t find a way so I modified the core code a bit. See below. It’s just a nasty hack but it works for me. Are there any plans to support this via an API call or event? I tried creating a plugin at first, but there’s no suitable event to attach the plugin to.

    Maybe adding an event where I now have my little hack?

    EDIT: I noticed that moving the hack to just before the ’return $documentObject;’ statement preserves your template variables. Because the next query uses the template variable this makes sense.

    From: document.parser.class.inc.php
            # this is now the document :) #
            $documentObject = $this->fetchRow($result);
           
    // Start template override hack
            $overrideTemplate=$_REQUEST['template'];
            if ($overrideTemplate!="") {
              $documentObject['template']=$overrideTemplate;
            }
    // End template override hack
    
            // load TVs and merge with document - Orig by Apodigm - Docvars
    
    • Actually, this should be done in the CSS, without bothering the template at all.

      http://www.alistapart.com/articles/goingtoprint/
        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
        • 21301
        • 93 Posts
        Quote from: sottwell at Aug 14, 2005, 03:14 PM

        Actually, this should be done in the CSS, without bothering the template at all.

        http://www.alistapart.com/articles/goingtoprint/
        I agree.

        I’m a big fan of CSS myself but there’s enough sites still that don’t use CSS. Why not have people do the same thing without CSS?
          • 1764
          • 680 Posts
          I was thinking something like this would be handy for handheld friendly themes. I think we should have some sort of an OnTemplateChoose plugin so that we could override a documents theme for handhelds, printer friendly, low-bandwidth, multi-lingual, etc.

          This could even be handy something like turning your whole site into an psuedo intranet based in originating IP address.
            • 22097
            • 37 Posts
            There is the option to include a snippet as your main template. This snippet can then determine the correct chunk (representing the real template) to insert. You’ll loose the ability to cache documents if using this method I guess.

            But adding a new Event to the plugin structure could open up some doors. An event fired as soon as someone requests a page. The event could pass the requested ID, and some other params, so that a plugin could choose to redirect the ID to another. I see another line of endless possiblities.... shocked

            With this event one could implement a multi-language site by redirecting to the correct language ID, restrict access to documents in some way, edit or validate parameters given with POST/GET.

            I’ve added it to the feature requests in the bug tracker.
              • 4673
              • 577 Posts
              Or even being browser based!


              Cool idea!
                Tangent-Warrior smiley
                • 32963
                • 1,732 Posts
                Sure you can do that with TP3.1

                Just use the OnWebPageInit event to check for type of browser device, etc then redirect to another page or perform some other action.
                  xWisdom
                  www.xwisdomhtml.com
                  The fear of the Lord is the beginning of wisdom:
                  MODx Co-Founder - Create and do more with less.
                  • 22097
                  • 37 Posts
                  Quote from: xwisdom at Aug 15, 2005, 02:42 PM

                  Just use the OnWebPageInit event to check for type of browser device, etc then redirect to another page or perform some other action.

                  Cool, I’ll certainly have a look at that. Any more undocumented events? grin
                    • 21301
                    • 93 Posts
                    Quote from: xwisdom at Aug 15, 2005, 02:42 PM

                    Just use the OnWebPageInit event to check for type of browser device, etc then redirect to another page or perform some other action.
                    I found the OnWebPageInit event. It’s invoked just before the parser call in index.php. You could surely detect the webbrowser here and redirect. It’s the perfect event for handling multi-language issues.

                    But for eg a low-bandwidth page it’d be usefull to change the template in the documentObject. Which can’t be done using the OnWebPageInit event since it’s called before the parser.

                    I’m trying to think of any other use for overriding settings in the documentObject. Can’t think of any other than the template smiley
                    • I wonder if the documentObject could be used in a multilanguage situation...hmm. Have to look into that.
                        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