We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30497
    • 245 Posts
    I need to create "print" versions of certain documents (articles, news items, timetable) and want to understand the best approach to this in MODx.

    Obviously, I will have a "print" CSS file for putting my main content into the printable format I desire.

    My requirements are to take the main content only, no sidebar information will be in a printable version of a document. The web user will simply click a link to the printable version of a page, at the bottom of each article.

    I saw this, CSS Switcher:
    http://modxcms.com/CssSwitcher-855.html

    Which looks like it will do the job, but I also wanted to see if there were ways to approach this using the core MODx features.

    Thanks.
      • 4385
      • 372 Posts
      How about something like this?

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

        * {
          visibility: hidden;
        }
        
        #content * {
          visibility: visible;
        }
      
        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.
        • 727
        • 502 Posts
        Definitely the best way (IMO) is to use CSS only, setting display: none and visibility: hidden as bwente suggested. Then you don’t need a print link - it will be automatic.

        Andy
          • 30497
          • 245 Posts
          Quote from: Andy at Apr 17, 2008, 02:57 PM

          Definitely the best way (IMO) is to use CSS only, setting display: none and visibility: hidden as bwente suggested. Then you don’t need a print link - it will be automatic.

          Andy

          Yes, I see now. I will use a javascript to add a print link as well on the page, as I need to emulate the current functionality of the site (I am changing the site from asp to new php/MODx backend) as per the site owner’s wishes.

          But I learnt something new again, and this method also saves me the problem that I had to solve with the previous asp design - duplicate content issues through the old programmer creating an entire new document for every print version, and then not blocking the print versions in robots.txt

          thanks guys.

            • 4385
            • 372 Posts
            Hooray! One more asp driven site taken off the web.

            BTW - You can also add information to the print version by doing the opposite and hiding the content on screen and making it visible when printed.

              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.
              • 30497
              • 245 Posts
              Quote from: bwente at Apr 17, 2008, 05:52 PM

              Hooray! One more asp driven site taken off the web.

              BTW - You can also add information to the print version by doing the opposite and hiding the content on screen and making it visible when printed.



              Ok, I’ll keep that in mind.

              yes, one less asp site!

              The only nagging problem I have with this method is that the user, when clicking print, doesn’t get an automatic preview of how the printed page will look. Do you now if there is a way I can do that? This is my current script for the user to call the print function from the content of the page (I don’t write java script, I pulled this one from a free web resource):
              <script type="text/javascript"><!--
              if (window.print) {
                  document.write('<input type="image" src="/assets/images/print.gif" mce_src="/assets/images/print.jpg" style="float:left" mce_style="float:left" onclick="window.print()"'+
                                 ' value="Print This Page">'); }
              // --></script>
                • 30497
                • 245 Posts
                Quote from: ganeshXL at Apr 18, 2008, 02:58 AM

                Well, if you want to have a print-style preview inside the regular browser (not via print-menu), then you’ll have to do some kind of CSS-switching via snippet.


                <?php
                
                // snippet [!styleItTakes!]
                
                $default = 'screen.css';
                $print = 'print.css';
                
                $css = $default;
                
                
                if($_GET['style'] == 'print') {
                	$css = $print;
                }
                
                return($css);
                
                ?>
                


                in your template:

                <link rel="stylesheet" href="assets/css/[!styleItTakes!]" type="text/css" media="screen" />
                <link rel="stylesheet" href="assets/css/print.css" type="text/css" media="print" />
                


                Your print link would then be something like:
                <a href="[~[+id+]~]?style=print">print this page</a>




                thanks, I’ll look into it.
                  • 10839
                  • 51 Posts
                  I was looking for a clean way to get this done in MODx, and I am happy to find it already solved.

                  By the way, towerofbabel, did it work?
                    GinerBosk smiley

                    If you can dream it, you can do it.
                    • 29076
                    • 615 Posts
                    No, it didn’t work. I get the correct style on the screen-pages, but on the pages with my-print-link I get this URL:
                    http://lrkh.no/index.php?id=107&submenuheader=0


                    The print-link have this URL:
                    http://lrkh.no/index.php?id=107?style=print
                    and it goes directly to my cant’t-find-page. smiley

                    My snippet code:
                    <?php
                    // snippet [!styleItTakes!]
                    
                    $default = 'lrkh.css';
                    $print = 'lrkh-print.css';
                    
                    $css = $default;
                    
                    
                    if($_GET['style'] == 'print') {
                    	$css = $print;
                    }
                    
                    return($css);
                    ?>
                      I think, thererfor I am! But what I am, and why...?
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      Whenever you code a URL, if you are NOT using friendly URLs, you have to use a &, not a ? for the query string. If you ARE using friendly URLs, then use a ?.
                        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