We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3032
    • 4 Posts
    I’m wondering if it’s possible to assign an alternate template to a page by posting a variable to the URL. For example, in Xaraya, I can create a link as follows: http://www.afterall.net/books/490886?theme=print. "?theme=print" tells Xaraya to override the default template with a print view template. I’m trying to do this for two reasons: 1) Sometimes people like to read an article unadorned, 2) Even though my CSS stylesheet for "media=print" includes "display:none" for a number of elements that I want to hide in the print view, Mozilla and Safari both print those elements anyway.

    I can achieve an alternate view on the screen by using the included styleswitcher.js, but printing still displays the elements I’ve hidden in the stylesheet. So, I’m wondering if I could actually have an alternate template for printing within modx, and force a page to use that template through the URL or some other manner. I’m trying to accomplish this at: http://agape.ie/move/campus/go/smallgroups. Click on "PrintView" to sample my attempts via the styleswitcher. (Caveat: this link is to a Christian website.)
      • 25663 MODX Staff
      • 12,272 Posts
      I think the biggest problem is that you declare the same CSS file for both print and screen:
      <link title="Agape" rel="stylesheet" type="text/css" href="/assets/templates/agape/agape.css" media="screen" />
      <link title="Agape" rel="stylesheet" type="text/css" href="/assets/templates/agape/agape.css" media="print" />
      <link title="Print"  rel="alternate stylesheet" type="text/css" href="/assets/templates/agape/print.css" media="screen" />


      Most likely, you need to remove the middle declaration and change the last one to media="print" as follows:

      <link title="Agape" rel="stylesheet" type="text/css" href="/assets/templates/agape/agape.css" media="screen" />
      <link title="Print"  rel="alternate stylesheet" type="text/css" href="/assets/templates/agape/print.css" media="print" />



        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 3032
        • 4 Posts
        You’re right, rthrash. I feel silly for having missed those typos. Now that I’ve fixed them, printing is functioning correctly. I’m still curious if you can force a page to use an alternate template since I can imagine other uses for it, but there’s no urgency now.

        I did leave the middle declaration in because it’s apparently necessary for the document to display correctly on screen using the styleswitcher.

        Thanks much, rthrash.
          • 25663 MODX Staff
          • 12,272 Posts
          You could then do this and not have two server requests:

          <link title="Agape" rel="stylesheet" type="text/css" href="/assets/templates/agape/agape.css" media="all" />
          <link title="Print"  rel="alternate stylesheet" type="text/css" href="/assets/templates/agape/print.css" media="screen" />


          A plugin could handle your other request, though the details around which I have no clue how to implement successfully.

            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me