We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21560
    • 145 Posts
    Yes, that’s possible, but it escapes me at the moment.

    I know you can get the ID in PHP using something. But I forgot what it was.

    Using that, you could set the snippet in the template and use it like you propose.

    Can anyone remember what the code was for the current document id?
      [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
      • 7455
      • 2,204 Posts
      $modx->documentIdentifier

      greets Dimmy
        follow me on twitter: @dimmy01
        • 36571
        • 145 Posts
        So at the beginning of the snipper would I then need to set:

        $parent = $modx->documentidentifier;

        would this not just render the page that the snippet call is on, rather than the originating page?

        Sorry, my PHP skills are slightly below rudimentary.
          • 21560
          • 145 Posts
          Theoretically, yes. BElow the <?php of course. Else it won’t work.

          The point is that I’m not sure if that will return an ID or an Alias (if aliasses are enabled).
            [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
            • 7455
            • 2,204 Posts
            it will return the id of the current page
              follow me on twitter: @dimmy01
              • 36571
              • 145 Posts
              By applying the changes I now get an error:

              Fatal error: Call to undefined function getDocument() in /var/www/web56/web/manager/includes/document.parser.class.inc.php(769) : eval()’d code on line 60

              All I did was comment out the old code and replace it with the one you posted.

              Any ideas on this?
                • 21560
                • 145 Posts
                Whoopsie, that’s what you get for quick’n’dirty jobs. I forgot to write $modx->getDocument instead of just getDocument.

                I’ve edited my ’orignal’ post. It just means that it’s not a global function. Which it isn’t, it’s a $modx function.
                  [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
                  • 36571
                  • 145 Posts
                  OK, that worked! Thanks.

                  I also managed to set $parent = $modx->documentIdentifier

                  However, the output PDF is now just a copy of the blank document with the makepdf snippet call. How can I implement it so that it creates a PDF of a document with content?
                    • 21560
                    • 145 Posts
                    Well that depends on how you want to use it. Instead of setting the $par that way...

                    Hold on...

                    If you want to have a link in the template that calls that snippet, making a PDF of the current page, things get a little more complicated.

                    Pfff... Let me think. You’d have to make a page that takes a variable that the plugin can use as input (namely, the document ID). Unfortunately I have no idea how to do that exactly. Well, I know how to do it in PHP, but I’m not sure if it would work with rewrites.

                    Anyway, then you’d have to modify the snippet, again, to take that value as input. Say for example: $par = $_GET[’documentid’];

                    That would get the document id from the variable documentid, used like such: index.php?id=111&documentid=2

                    Where ID is the id of the page where you call the snippet and document ID is the page you want PDF-ed.

                    And... I THINK you could do this by adding the following link to the template: <a href="index.php?id=111&documentid=[*~id~*]">Get PDF</a>

                    Because, if I recall this all correctly, [*~id~*] gets replaced by the document ID of the page you’re viewing. This is all me thinking out loud, though ;-) Please forgive me if it blows up your computer. It shouldn’t as such... But you know, computers have been known to do stranger things.
                      [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
                      • 36571
                      • 145 Posts
                      Hey Nimja. You rock!

                      That worked (almost) perfectly.

                      I added the following link to the template
                      <a href="[~14~]?documentid=[*id*]">Get PDF</a>
                      where 14 is the document containg the MakePDF snippet call and set

                      $parent = $_GET['documentid'];
                      at the beginning of the snippet. It now outputs the page on which the link is clicked. Perfect.

                      Now just have to get onto editing the template.

                      Thanks again for your help. Great snippet!