We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9192
    • 5 Posts
    Hi,

    I’m using ditto to output some documents through a chunk. Ditto doesn’t seem to allow me to truncate specific placeholder text so I thought I’d just call a snippet from within the chunk and do my truncating from php. But so far while the call to the snippet works I can’t figure out how to pass it the text.

    Example chunk below.

    <h2><a href="[~[+id+]~]" title="[+title+]">[+longtitle+]</a></h2>
    
    This is the placeholder I want to truncate: [+content+]
    <br/>
    This is calling the truncate snippet: [[TruncateText? &truncText='[+content+]' ]]
    


    Thanks for any help.

    Evan
      • 7231
      • 4,205 Posts
      Try with backticks not single quotes grin
      [[TruncateText? &truncText=`[+content+]` ]]
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 9192
        • 5 Posts
        Yes I tried that before.

        This causes the snippet call to fail and the chunk just displays:

        [[truncateText? &truncText=`content text here
        ` ]]

        "content text here" being the placeholder text.
          • 3749
          • 24,544 Posts
          I don’t see why what you’re doing shouldn’t work (especially with the back-ticks in place), but what about sending the document ID (e.g. &docID=`22`) in the snippet call instead of the content itself.

          Then your snippet code could do this:
          $doc = $modx->getDocument(&docID);
          $output = $doc[‘content’];
          
          // truncate $output here
          
          return $output;


          Alternately, you could just fill in the summary field for each document. Make it a truncated version of the content (you could write code to automate this) and then use the summary TV instead of the content TV.

          Bob


            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 9192
            • 5 Posts
            Thanks Bob,

            I managed to pass the doc id but not the way you suggested. I had to drop the quotes:

            [[TruncateText? &docId=[+id+] ]]


            Using id works this way because there are no spaces in the document id, but if there are spaces in the passed variable the call fails. This is fair enough but, why do any form of quotation marks cause the snippet call to fail?

              • 28042 ☆ A M B ☆
              • 24,524 Posts
              That should be backticks `...` not any kind of quote marks.
                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
                • 9192
                • 5 Posts
                By any kind of quote mark I included back tics `...`

                It makes no difference using back tics, the call still fails in the same way.
                  • 25663 MODX Staff
                  • 12,272 Posts
                  You might call the snippet uncached.
                    Ryan Thrash, MODX Co-Founder
                    Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                    • 9192
                    • 5 Posts
                    Yes I tried this too.

                    [!TruncateSnowReportText? &docId=`15` !]


                    Is the response. So the snippet call fails.

                    But don’t worry I took BobRay’s initial sugesstion and just passed the document id. It doesn’t contain spaces so doesn’t need to use back ticks.

                    Thanks!
                      • 3749
                      • 24,544 Posts
                      Quote from: Evan111 at Jan 03, 2008, 04:30 AM

                      I took BobRay’s initial sugesstion and just passed the document id. It doesn’t contain spaces so doesn’t need to use back ticks.

                      I don’t know enough about MODx’s inner workings to be sure, but I think passing the document ID will also be a little faster and put less demand on the server than passing the entire contents of the document as a parameter.

                      Bob
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting