We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2091
    • 44 Posts
    I have a page on a gardening site that pulls several hundred plants from a database. Each plant is linked to more information about that plant. Instead of creating a separate page for each plant, I pass a plant id parameter in the URL.

    Each plant is supposed to allow comments to be posted about it. My problem is, with Jot, I can insert the main plant pages url, but how do I insert the plant id so the comments will display for the appropriate plant? Or is there another way to do this with Jot?

    Thanks.
      • 19726
      • 239 Posts
      I think this can be done with the "tagid" parameter. The Jot demopages had an example for adding comments to pictures which shows how it works, but the pages seem to be offline. This page on the Wiki also has a short example http://wiki.modxcms.com/index.php/MaxiGallery#Photo_blogging_with_Jot

      If I am correct you should just put your plantid as the value of "tagid" and it should work I think.
        • 2091
        • 44 Posts
        Where do I put the ’tagid’? In my snippet call?
          • 2091
          • 44 Posts
          Okay, I created a chunk called {{TagId}} that calls a snippet that uses GET to print the plantid from the url. Then I modified the jot template to add a hidden variable called "tagid" with a value of {{TagId}}. When I make a comment it puts the appropriate value in the tagid field in the db. But the comment shows up on all the pages with that parent id.

          How do I get it to check the tagid? I put &tagid=`{{TagId}}` in my jot snippet call but that didn’t work.

          Any more help would be greatly appreciated.

          Thank you.
            • 19726
            • 239 Posts
            I just tried the example inthe Wiki and I got it working as follows

            First make a snippet that gets the plantid and puts it in a placeholder. Make sure this snippet is placed before the Jot call on your page. In my test I had this code in the snippet.
            $modx->setPlaceholder('test.id', $_GET['testid']);


            Next add "&tagid=`[+test.id+]`" to your Jot call. In my test the Jot call looked like this
            [[Jot? &tagid=`[+test.id+]`]]


            Thats all. When I add "?testid=1" to the URL and make a comment then I won’t see that comment when I use "?testid=2" in the URL. When going back to "?testid=1" then the comment shows up again.

            When you are going to apply this on a real site the I would suggest some extra checking on the id parameter to make sure it is an actual plant id.

            Oh, and make sure the you use uncached snippet calls or have the page uncached.
              • 2091
              • 44 Posts
              Thank you very much for your help.

              However, this doesn’t seem to be working for me. I created a snippet to the plantid value and set it in a placeholder.
              $modx->setPlaceholder('plant.id', $_GET['plantid']);

              And that works. I put the placeholder above the Jot call and it displays the correct plantid.

              And then my Jot call looks like this
              [!Jot? &tagid=`[+plant.id+]`]]


              But, when I submit a comment, it just puts "[plantid]" in the tagid field in the db.

              Thanks again.
                • 19726
                • 239 Posts
                Weird, I tried to get my example working again and it would not work :’(

                But I was able to find another solution. I used the snippet below and it worked. Basically it skips the placeholder step and calls the Jot snippet from within the snippet you use to get the plantid from the URL.
                <?php
                $params['tagid'] = $_GET['testid'];
                return $modx->runSnippet('Jot', $params);
                ?>

                The runSnippet call takes the snippetname and an array with snippet parameters as input. See http://wiki.modxcms.com/index.php/API:runSnippet for more info.
                  • 2091
                  • 44 Posts
                  Thanks Mitch! It works perfectly! You are a life saver!
                    • 19726
                    • 239 Posts
                    Glad to hear that it works. But before using it on a live site make sure to check that you check if the plantid from the URL is a valid one. Otherwise people can create "hidden" comments by adding "?plantid=my_secret_comments" to the URL.