We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33393
    • 30 Posts
    Didn’t see anything like this so I canabalized something together. Are there any security issues with this? I guess I could strip tags on the print variable. And I don’t know if it will work with url rewrite. :| Sorry. I’d also like to have it redirect if there is no such id, but haven’t figured that out yet.

    I made a print page (whose id is 95 in this case) with this snippet in content.
    [[PrintArticle]]

    Then in my article template I put the following link:
    <img src="print icon of your choice" /> 
    <a href="index.php?id=95&print=[*id*]">printer friendly format</a>
    


    Snippet code:

    $print = $_GET['print'];
    
    $sql = "SELECT id, longtitle, content, createdon FROM 
    (insert your database info here) a WHERE a.type = 'document' 
    AND a.isfolder = '0' and a.deleted = '0' and a.id = $print LIMIT 1";
    
    $getall = $modx->db->query($sql);
    if ($getall){
    while ($row = $etomite->fetchRow($getall)) {     
    $output .= "<div class='entry'><h3>".$row['longtitle']."</h3>"; 
    $output .= "<div class='entrybody'>".$row['content']."<br></div>";
    $output .= "<div class='author'>".strftime("%B %e, %Y", $row['createdon']). "</div>"; 
    $output .= "</div>";
         }
    }
    return $output;
    
      "Adversus solem ne loquitor." -don’t speak against the sun (don’t waste your time arguing the obvious) Something I sometimes need to be reminded of.
      • 18397
      • 3,250 Posts
      There are several problems with you using that sql line. Try using the http://modxcms.com/getdocumentchildren.html API.
      • And it would be more "MODx" to do:

        <img src="print icon of your choice" alt="print page" /> 
        <a href="[~95~]&print=[*id*]">printer friendly format</a>
        


        Although it would be best of all to simply provide an alternate CSS file for media="print" in your individual articles template wink

        http://www.alistapart.com/stories/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
          • 33393
          • 30 Posts
          I really like modx, I’m having a lot of fun digging into it. I think I started using these sql queries because in some of my menus and blog-type story retrieval I wanted to get all stories from almost all folders, but exclude a few. Maybe there’s a better way to do this?

          Maybe it’s the way I set things up. I made a topics folder then I set up a different parent folder for each topic under the topics folder. And then on the front page I want to be able to retrieve all those topic folders no matter how many I add, but I don’t want to display folders and I don’t want to display any documents from other folders.

          I’m thinking of adding another table for topic categories, and a topic field in the site_content table to avoid making folders altogether and just put everything in the topics folder and select by that topic field.
            "Adversus solem ne loquitor." -don’t speak against the sun (don’t waste your time arguing the obvious) Something I sometimes need to be reminded of.
            • 33393
            • 30 Posts
            Quote from: sottwell at Dec 16, 2005, 10:57 AM

            And it would be more "MODx" to do:

            <img src="print icon of your choice" alt="print page" /> 
            <a href="[~95~]&print=[*id*]">printer friendly format</a>
            


            Although it would be best of all to simply provide an alternate CSS file for media="print" in your individual articles template wink

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

            That’s a good thing to remember ie
            [~95~]


            I should have thought of using the style sheet, I’ve done that before.

            I’ve been learning php, but I’ve got to tell you that playing with modx has donr more to help me learn than anything else.
              "Adversus solem ne loquitor." -don’t speak against the sun (don’t waste your time arguing the obvious) Something I sometimes need to be reminded of.
            • One thing to keep in mind (which thing bit me in the backside recently) is that the basic parser evaluation of that [~95~] is to "index.php?id=95". In that case, your added query string argument needs to be &print=whatever, since the ? is already being used for the MODx generated link. But if the site is using friendly URLS, it will want to be ?print=whatever. There’s a bit of nice code that’s good to plug into any snippet you make that will be adding to the query string:

              // if friendly urls or not
              $furls = $modx->config['friendly_urls'];
              $char = $furls ? '?' : '&';
              


              This checks to see if "friendly_urls" is 1 or 0 and assigns the $char value accordingly. Just use the variable in your code like so:

              $theLink = '<a href="[~95~]'.$char.'print=[*id*]">printer friendly format</a>';
              


              It will then use the appropriate character for either form of link.
                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
                • 33393
                • 30 Posts
                Quote from: zatoichi at Dec 16, 2005, 08:13 PM

                I really like modx, I’m having a lot of fun digging into it. I think I started using these sql queries because in some of my menus and blog-type story retrieval I wanted to get all stories from almost all folders, but exclude a few. Maybe there’s a better way to do this?

                Maybe it’s the way I set things up. I made a topics folder then I set up a different parent folder for each topic under the topics folder. And then on the front page I want to be able to retrieve all those topic folders no matter how many I add, but I don’t want to display folders and I don’t want to display any documents from other folders.

                I’m thinking of adding another table for topic categories, and a topic field in the site_content table to avoid making folders altogether and just put everything in the topics folder and select by that topic field.

                I figured out a way to use the $modx->select and get the result I want. Simply I use one template for all my article entries and use that template id number in my WHERE clause. I can get all stories across all folders and only the ones with my article template will be selected.

                $modx->db->select(
                "id, pagetitle", $table, "isfolder = 0 AND template = 10", 
                "createdon DESC", "$L");


                Works like a charm. I feel better now.
                  "Adversus solem ne loquitor." -don’t speak against the sun (don’t waste your time arguing the obvious) Something I sometimes need to be reminded of.
                  • 33393
                  • 30 Posts
                  Quote from: sottwell at Dec 17, 2005, 11:44 AM

                  One thing to keep in mind (which thing bit me in the backside recently) is that the basic parser evaluation of that [~95~] is to "index.php?id=95". In that case, your added query string argument needs to be &print=whatever, since the ? is already being used for the MODx generated link. But if the site is using friendly URLS, it will want to be ?print=whatever. There’s a bit of nice code that’s good to plug into any snippet you make that will be adding to the query string:

                  Is
                  $modx->config['friendly_urls']
                  in the api list? But I sense that I could use config for any such field available wherever those config variables are located?
                    "Adversus solem ne loquitor." -don’t speak against the sun (don’t waste your time arguing the obvious) Something I sometimes need to be reminded of.
                  • Yes, the $modx->config[] array contains all the site configuration values from the database, and a few dynamically calculated values as well, I believe. The whole list is available here; it returns the same values as the "settings" tag:

                    http://www.modxcms.com/modx-tags.html

                    I’ve also just discovered the API function getConfig (that document.parser.class.inc.php file makes for some very interesting reading):

                    $modx->getConfig('site_name');
                    


                    which will do the same thing. So there’s three different ways of getting the same info, all depending on how you want/need to do it. The [(...)] tags are available for templates, documents and chunks, while either the array and the API function are available for snippet, plugin or TV code.

                    You can view the full list raw if you stick this in a snippet; it might even be useful to print this out and keep handy:

                    echo "<pre>";
                    print_r($modx->config);
                    echo "</pre>";
                    exit();
                    


                    (the getConfig() API function isn’t in the documentation yet...)
                      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