We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18397
    • 3,250 Posts
    Allowing XML conditionals would mean you would only need one chunk to template Ditto. For example, here is a chunk that could be used for RSS:

    <ditto:header>
    <?xml version="1.0" encoding="[+rss:encoding+]"?>
    		<rss version="2.0">
    			<channel>
    				<title>[*pagetitle*]</title>
    				<link>[+rss:link+]</link>
    				<description>[*description*]</description>
    				<language>[+rss:lang+]</language>
    				<copyright>[+rss:copyright+]</copyright>
    				<ttl>[+rss:ttl+]</ttl>
    </ditto:header>
    <ditto:item>
    				<item>
    					<title>[+rss:pagetitle+]</title>
    					<link>[(site:url)][~[+id+]~]</link>
    					<description><![CDATA[ [+summary+] ]]></description>
    					<pubDate>[+rss:date+]</pubDate>
    					<guid>[(site:url)][~[+id+]~]</guid>
    
    					<author>[+rss:username+]</author>
    				</item>
    </ditto:item>
    <ditto:footer>
    			</channel>
    </rss>
    </ditto:footer>
    


    The only problem is that parsing the XML to separate the template items and conditions requires time. Is it worth it?
      • 25663 MODX Staff
      • 12,272 Posts
      Interesting question. If it’s resource intensive, I’d say no. But bs would be one to ask about this since he’s made an XML parser for PHP4 for Replix.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 18397
        • 3,250 Posts
        Actually, there is no XML parser involved. Its a simple regex.
          • 18397
          • 3,250 Posts
          Here is the actual parser code that Victor gave me a hand with a while back:

          <?php
          
           // ---------------------------------------------------
          // template class
          // ---------------------------------------------------
          class template {
          
          
              function fetch( $path ) {
                  $fp = @fopen( $path, "r" );
                   if ( $fp ) $template = @fread( $fp, filesize( $path ) );
                   else $template = '';
                   return $template;
                   }
          
          
              function split( $tplContent ) {
                  $sections = array();
                   $matches = array();
                   if ( preg_match_all( '/<ditto:(header|item|footer)>(.*?)<\/ditto:\\1>/s', $tplContent, $matches, PREG_SET_ORDER ) ) {
                      foreach ( $matches as $match ) {
                          $sections[$match[1]] = $match[2];
                           }
                      } else {
                      return "No matches!\n";
                       }
                  return $sections;
                   }
          
          
              function replace( $placeholders, $tpl ) {
                  $output = "";
                   $output = str_replace( array_keys( $placeholders ), array_values( $placeholders ), $tpl );
                   return $output;
                   }
          
          
              function parse( $tplurl, $tplfield, $tplplaceholders = false ) {
                  $code = $this -> fetch( $tplurl );
                   $field = $this -> split( $code );
                   $output = $field[$tplfield];
                   if ( $tplplaceholders ) {
                      $output = $this -> replace( $tplplaceholders, $output );
                       }
                  return $output;
                   }
          
          
          
          
              }
          // end
          ?>
          
            • 32963
            • 1,732 Posts
            Sounds ok to me. I like the idea of using a single chunk but I’m also of the opinion that you should still allow usings to use mutiple chunks if they want to.

              xWisdom
              www.xwisdomhtml.com
              The fear of the Lord is the beginning of wisdom:
              MODx Co-Founder - Create and do more with less.
              • 22815
              • 1,097 Posts
              I can imagine that I might have a site with 2 news pages where all but one of the chunks used were the same; having a single XML for each page would mean duplicating stuff.

              I still think that I’d like this sort of facility at the MODx level such that &xmlParameters would work on ANY snippet and let you load in parameters from a chunk.

              Whether at the MODx level or at the Ditto, if you do this I’d also like &xmlFileParameters or whatever so that I could load in the XML from a file rather than a chunk. That would be great for development.
                No, I don&#39;t know what OpenGeek&#39;s saying half the time either.
                MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
                Forum: Where to post threads about add-ons | Forum Rules
                Like MODx? donate (and/or share your resources)
                Like me? See my Amazon wishlist
                MODx "Most Promising CMS" - so appropriate!
                • 15987
                • 786 Posts
                Mark,
                A similar discussion was started in the wayfinder thread about using a similar approach (not with xml though). I think we should decide on a standard way to create themes/templates for all core distributed snippets so we don’t re-invent the wheel for each one.

                I think this is a good idea, it would make it very easy to share different themes/layouts with other users.

                Here is a link to the discussion we had on wayfinder. I haven’t started working on a solution yet and am still open to new ideas on it. http://modxcms.com/forums/index.php/topic,5801.msg41537.html#msg41537
                  • 18397
                  • 3,250 Posts
                  Personally, I like the full template vs the parameters because then you see the actual output of the snippet in blocks (which sections repeat and whatnot). This would make it easier to theme.

                  I’ve got everything else in Ditto 1.1 finished so this is the only thing delaying its release.

                  (Ditto 1.1 has many major changes in parameters that keep it from being 1.0.3)