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

    I want the "usual" news ticker which is dynamically feeded through a news blog. One way to do this is putting a @EVAL in the Default value of the template variable:
    @EVAL
    $tbl = $modx->getFullTableName('site_content');
    $id = 74;
    $rs = $modx->db->query( "SELECT PageTitle, Content FROM $tbl WHERE parent = $id AND published = 1" );
    $result = '';
    while ($row = $modx->db->getRow($rs)) {
      if ($result != '') $result .= '||';
      $result .= '<div class=\"na_row\"><h3>' . $row['PageTitle'] . '</h3><div class=\"na_content\">' . $row['Content'] . '</div></div>';
    }
    return $result;


    This is all very nice but why not use Ditto to do this? The adavantage would be that I can use a template for the layout which is more readable than the chunk of code. I thought about the following (assuming the news is in folder with id 10 and the document with the ditto snippet has id 11):


    • Create a document with the following ditto call in the contents:
    [!Ditto? &folder=`10` &tpl=`NewsTickerRowTpl` &tplLastRow=`NewsTickerLastRowTpl` &summarize=`100` !]

    • Create the 2 templates as you like, BUT put || as the last row in the NewsTickerRowTpl
    • In the default value of the template variable write:
    @DOCUMENT 11


      [li]In some other document refrence the template variable [*...*].

    When viewing "index.php?id=11" the contents is as expected: a nice list of news separated by ||.

    When viewing the document which references the template variable I get the following error:

    « MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource:
    « PHP Parse Error »

    PHP error debug
    Error: array_values() [function.array-values]: The argument should be an array
    Error type/ Nr.: Warning - 2
    File: C:\Documents and Settings\ronald\Documenti\My Projects\CMS\modx-0.9.2.1\manager\includes\document.parser.class.inc.php(705) : eval()’d code
    Line: 371

    Parser timing
    MySQL: 0.0384 s s (10 Requests)
    PHP: 0.2352 s s
    Total: 0.2736 s s

    Any Idea?

    Thanks,

    Ronald

    Ps. Sorry if this is an oldy but I didn’t find any info about it...
      • 7923
      • 4,213 Posts
      At some point of Ditto developement, that parse error came up if no documents are found to return.. but it’s been fixed in newest releases (betas).


        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 29577
        • 11 Posts
        Ok, with that Ditto 1.1 Beta 1 the parse error is away.
        BUT the next problem is interesting:

        when the TV parses the @DOCUMENT it simply get’s the contents ([!Ditto]) and tries to split that instead of the contents generated by Ditto.

        I use MODx 0.9.2.1 (rev 1005), is this by design or a bug?

        Thanks,

        Ronald
          • 7923
          • 4,213 Posts
          use @eval $modx->runSnippet(’Ditto’, array of params)


            "He can have a lollipop any time he wants to. That's what it means to be a programmer."
            • 29577
            • 11 Posts
            Ok, that runs smoothly, thanks a lot.

            You’ve a great tool here.

            Ronald
              • 33033
              • 43 Posts
              Old thread, but I’m trying to do the same thing and I cannot get this working. Wondering if anyone can help me. Using MODx 0.9.5/Ditto 1.02 right now. I finally got it so the ticker + Ditto works (Should really learn PHP at some point wink), but the result looks like so:
              \r\n
              \r\n
              \r\n\"\"\r\n
              \r\n
              \r\n
              Title
              \r\n
              \r\n
              \r\nMy content goes here.\r\n
              \r\n
              
              0 Comments
              \r\n
              \r\n
              \r\n
              \r\n
              
              Read the full article (link gets shown as http://yankeedeuce.com/%5C%22features/article-1162623473.php%5C%22 )
              \r\n
              \r\n
              \r\n
              \r\n



              Not sure why it’s doing this, you can see what it looks like now at www.yankeedeuce.com, and what the Ditto tpl should be output as in the ticker above it.


              My NewsTicker TV looks like this (line breaks for readability):

              @EVAL 
              $params = array(); 
              $params['displayArchive'] = '0'; 
              $params['tpl'] = 'DittoFeatured'; 
              $params['tplLastRow'] = 'DittoLastRow'; 
              $params['startID'] = '2'; 
              $params['summarize'] = '5'; 
              $params['sortBy'] = 'pub_date'; 
              $params['total'] = '5'; 
              return  $modx->runSnippet('Ditto', $params);
              
              

              Any help would be appreciated grin
                • 18397
                • 3,250 Posts
                1. What is the contents of DittoFeatured and DittoLastRow?
                2. Try stripping out all newlines from the chunks mentioned in #1 so they all are on a single line.
                3. Use Ditto 2. Its faster, cleaner, and much better documented.