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

    Sorry to bring up this topic again, but I am going out of my mind! I have one snippet call in my ditto rss template that works like a charm. But the next one is simply being printed out within the page and it’s driving me mad! It is obviously something I am doing but I cannot see what’s wrong. Could I get another set of eyes to look at the code?


    My RSS template:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    	<channel>
    		<title>My title</title>
    		<link>http://www.mysite.com/</link>
    		<description><![CDATA[Up-to-date information from My Site]]></description>
    [*content*]
    	</channel>
    </rss>


    My ditto call in a text/xml content type:
    [[Ditto? &startID=`98,100,52,51,70` format=`rss` &tpl=`rss_feed` &dateFormat=`%a, %d %b %Y %T %Z` &total=`20` &display=`20` &filter=`id,58,2|id,56,2|id,57,2|id,72,2`]]


    My rss template:
    <item>  
    <title>[!cdata? &txt=`[+pagetitle+]`!]</title>
    <link>[(site_url)][~[+id+]~]</link>  
    <description>[!tiny? &txt=`[+content+]`!]</description>  
    <pubDate>[+date+]</pubDate>
    <guid>[(site_url)][~[+id+]~]</guid>  
    </item> 


    The working snippet (cdata):
    <?php
    if($txt) {
    	$output = '<![CDATA[' . $txt . ']]>';
    	return($output);
    }
    ?>


    The non-working snippet(tiny):
    <?php
    if($txt) {
    $tot_length = strlen($txt);
    $numb	 = isset($numb)? $numb:100;
    $numb = $tot_length < $numb? $tot_length : $numb;
    $find = "[";
    $position = stripos($txt, $find);
    
    $trunc	 = $position > $numb? $numb: $position;
    $output = "<![CDATA[ ";
    	$output .= substr($txt, 0, $trunc);
    	$output .= "...";
    $output .="]]>";
    	return($output);
    }else{
    $output = "no description available";
    return($output);
    }
    ?>


    This second snippet is meant to truncate the content dependant on whether modx tags are present or not. I need to do this because I want to exclude any maxigallery or other specialized content and just give a short preview of the content.

    Thanks to anyone can spot my errors.

    Sheri
      • 20682
      • 31 Posts
      Update:

      I added the summary extender to try that rather than my own snippet. The template is now:

      <item>  
      <title>[!cdata? &txt=`[+pagetitle+]`!]</title>
      <link>[(site_url)][~[+id+]~]</link>  
      <description>[!cdata? &txt=`[+summary+]`!]</description>  
      <pubDate>[+date+]</pubDate>
      <guid>[(site_url)][~[+id+]~]</guid>  
      </item>


      The summary description gets printed on the first go through, i.e. the summary is encased in the cdata tags as expected, but the second and subsequent loops print the snippet call directly rather than the parsed call.

      This is a good start, but I would still like to use my own snippet to remove the possibility of including any unparsed snippets contained within the content...which could be anything in the future.

      *FURTHER UPDATE*

      I plugged the "tiny" snippet back in and it revealed that the snippet *is* being parsed on the first loop round but not the second and subsequent. Additionally, the printed snippet call is no longer the uncached version...it appears cached.

      There was a small issue with the "tiny" snippet. Here is the debugged version:

      <?php
      if($txt) {
      $tot_length = strlen($txt);
      $numb	 = isset($numb) ? $numb:100;
      $numb = $tot_length < $numb? $tot_length : $numb;
      $find = "[";
      $pos = stripos($txt, $find);
      $pos = $pos > 0? $pos : $numb;
      $trunc	 = $pos > $numb? $numb : $pos;
      $text = substr($txt, 0, $trunc);
      $output = "<![CDATA[ ";
      	$output .= $text;
      	$output .= "...";
      $output .="]]>";
      	return($output);
      }else{
      $output = "no description available";
      return($output);
      }
      ?>

      Sheri
        • 20682
        • 31 Posts
        I’m sorry that no one had any ideas regarding my snippet problem. :’( I decided to create my own snippet for the rss feed since it was taking longer to mess about with ditto than to write my own php.

        Sheri
          • 7231
          • 4,205 Posts
          I had the same problem with snippets in the RSS feed. I resolved it by setting the feed document to cached, the ditto call uncached [! !] and the inner snippets cached [[ ]].

          It would not work by reversing the order; uncached document cached outer and uncached inner.
            [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]
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            If you understand how MODx process snippets, it is logical. When the parser sees [[...]] tags, it processes the snippet. If it uses another snippet as a parameter value, it gets stuck because that snippet hasn’t been processed yet, so the parameter has a bad value.

            When the parser sees [!...!] tags, it converts them to [[...]] tags and moves on; this snippet will be processed on the next pass through the parser. So if the OUTER snippet is uncached [!...!], it gets its tags converted and then the INNER snippet is processed.

            Now on the next pass, the outer snippet is processed (since its tags got converted to regular [[...]]), but this time its parameter value contains the output of the inner snippet (which got processed on the last pass), and all is well.

              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
              • 7231
              • 4,205 Posts
              I never get tired of reading about the cache. One day it will sink in. grin

              What had me lost is that for some reason I thought that the document cache settings would have an influence in the order of the [[ ]] [! !] sequence.
                [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]
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                No, but while that whole convert-tags business only occurs if the document is not cached (or the first time it’s parsed, if it’s cached), after the document is retrieved from cache there is a check for unprocessed snippet calls and placeholders. So even cached, a document may get a few passes through the parser.

                I’ll have more information on this when I get to "How MODx Snippets Work" in my series of articles; I’ll examine the parser’s code again (several times!) and run all kinds of tests to see exactly what it’s doing.
                  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
                  • 7231
                  • 4,205 Posts
                  I’ll have more information on this when I get to "How MODx Snippets Work" in my series of articles; I’ll examine the parser’s code again (several times!) and run all kinds of tests to see exactly what it’s doing.
                  Sweat Sweet  grin
                    [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]
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    Actually I do; writing this stuff is harder than reading it is shocked
                      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
                      • 7231
                      • 4,205 Posts
                      Oooops, that is a typo that I make more often than I would like to admit. tongue
                        [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]