We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21301
    • 93 Posts
    Quote from: jaredc at Aug 25, 2005, 08:23 AM

    Aw come on... it’s not THAT long! wink
    LOL It was long enough for me not to understand clearly what it did wink

    Glad you helped us out here! And sorry for misunderstanding.
      • 18397
      • 3,250 Posts
        • 8634
        • 56 Posts
        If only I could understand... what to exactly do to have this mod work with a print this page button...
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          All you need to make a page "printable" is have a second stylesheet linked in your template head.

          <link rel="stylesheet" type="text/css" media="print" href="assets/site/print.css" />
          


          Set your banner ad, your menu sidebar, and anything else you wouldn’t want printed to "display:none" in the CSS. Give the content div a nice width, and set the font to a nice printer font face and size.

          That’s it. The user’s browser does all the rest; when the user clicks on "print" the browser automatically uses the CSS file from the media="print" link.

          A good article on the subject:

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

          A bit of javascript to make a "Print" button:
          <form><input type="button" id="printbutton" value="Print This Page" onClick="window.print()"></form>
          
            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: eko40 at Aug 26, 2005, 05:22 AM

            If only I could understand... what to exactly do to have this mod work with a print this page button...
            You should use the css way as Susan describes. It’s the better option.

            Just to explain how the plugin works here’s how you could also do it:
            - First duplicate your main template and change it so that it prints nicely
            - You could also create a new template only having [*content*]
            - Name your new template ’printpagetemplate’
            - Create the snippet and plugin as shown below
            - Use [[printpagelink]] in your content where you want the link

            And optional:
            - Customize the snippet to your needs, use an image, add a target to open the link in
            - Add javascript to your printtemplate to open the print dialog automatically
            - Separate the content from the snippet by using Olaf’s tip wink
            http://modxcms.com/forums/index.php/topic,718.msg4149.html#msg4149

            Create a snippet printpagelink:
            // Set the name of the template used for printing
            $printtemplate="printpagetemplate";
            $id = $modx->documentIdentifier; // Get current document
            $link ="<a href=\"[~$id~]?template=$printtemplate\">print this page</a>";
            return $link;
            


            Since I used selecting the template by name, use this modified plugin:
            /*
             *  Written by: Theo Ketsinga
             *  Created: 8/2005
             *  For: MODx cms (modxcms.com)
             *  Name: ChangeTemplate
             *  Description: Enables template modification at runtime by parameter
             *  (selection by name)
             *  Events: OnLoadWebDocument
             *  Version: 1.1
             *
             *  Put this text into a new plugin and set the System Event
             *  'OnLoadWebDocument'. You can now override the template for a
             *  page by adding the parameter &template=<template_name> to a page.
             *
             */
            
            if (isset($_REQUEST['template'])) {
              $overrideTemplate=$_REQUEST['template'];
            
              $sql = "SELECT * FROM ".$this->getFullTableName("site_templates")." WHERE ".$modx->getFullTableName("site_templates").".templatename = '".$overrideTemplate."';";
            
              $result = $modx->dbQuery($sql);
              $rowCount = $this->recordCount($result);
              if($rowCount>1) {
                $this->messageQuit("Incorrect number of templates returned from database", $sql);
              } elseif($rowCount==1) {
                $row = $this->fetchRow($result);
                $modx->documentContent = $row['content'];
                $modx->documentObject['template']=$row['id'];
              }
            }
            

              • 8634
              • 56 Posts
              Many thanks Susan & Theo, this provides great insight in both options. I’ll experiment with it.
                • 4266
                • 70 Posts
                Quote from: theo at Aug 26, 2005, 02:05 PM


                - First duplicate your main template and change it so that it prints nicely
                - You could also create a new template only having [*content*]
                - Name your new template ’printpagetemplate’
                - Create the snippet and plugin as shown below
                - Use [[printpagelink]] in your content where you want the link

                Create a snippet printpagelink:
                // Set the name of the template used for printing
                $printtemplate="printpagetemplate";
                $id = $modx->documentIdentifier; // Get current document
                $link ="<a href=\"[~$id~]?template=$printtemplate\">print this page</a>";
                return $link;
                


                Since I used selecting the template by name, use this modified plugin:
                /*
                 *  Put this text into a new plugin and set the System Event
                 *  'OnLoadWebDocument'. You can now override the template for a
                 *  page by adding the parameter &template=<template_name> to a page.
                 */
                ...
                



                Print page link doesn’t work! Just nothing happens, only the page reloads.

                As I understand when user triggers [[printpagelink]] on the document page, this snippet triggers the ChangeTemplate plugin to reload this page with new template. But it doesn’t work with my MODx 3.2 web-site. And I don’t know why. Any ideas?
                  • 10558
                  • 23 Posts
                  The Etomite snippet quoted above is for admins to globally change all, or selective, pages to a new template, but it is a PERMANENT change, as the database table is updated.

                  I like your approach, but as I (at present) use Etomite, I am wondering if it can be amended so that it works for me.

                  Any thoughts ?
                    Gordon.
                    My Etomite web site http://www.gbtamc.co.uk/et
                    My main web site http://www.gbtamc.co.uk
                    My blog site http://www.gbtamc.co.uk/blog
                    My photo gallery http://www.gbtamc.co.uk/spgm
                    • 25663 MODX Staff
                    • 12,272 Posts
                    Sorry Gordon, but it won’t work. Etomite doesn’t support the plugins or events.
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                      • 21301
                      • 93 Posts
                      Quote from: bugaev at Sep 02, 2005, 08:01 AM

                      Print page link doesn’t work! Just nothing happens, only the page reloads.

                      I’ll have a look at the 1.1 version (select by name) of the plugin. I’m using the 1.0 (select by id) version myself. Can you tell me the URL of the printpagelink? And what URL do you see when the page reloaded?