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
    After much consideration, I decided to go with XML based templating for the next version of Ditto over the double placeholder technique that kylej helped me out with (REGEX HELP topic). The reason is very simple: you can collapse xml tags in any RTE but you can’t collapse [++tag++] and [++/tag++] in any.

    So, I whipped up a quick parser based on REGEX which works great. Except when it needs to handle recursive templates like the archive. It just plain fails. I need a function that can turn this:

    <ditto:archive>
    <h3>Archives</h3>
    <div id="ditto_archivelist">
       <ul id="ditto_ul">
           <ditto:year>
           <li><span class="ditto_year">[+year+]</span>
               <ditto:month>
               <li><span class="ditto_month">[+month+]</span>
                   <ul>
                       <ditto:item>
                       <li><a href="[~[+id+]~]">[+title+]</a> (<span class="ditto_date">[+date+]</span>)</li>
                       </ditto:item>
                   </ul>
               </li>
               </ditto:month>
           </li>
           </ditto:year>
       </ul>
    </div>
    </ditto:archive>
    


    Into an associative array containing the content of each template and only that template (not its children). Places where a subtemplate exists should be replaced with a ditto prefixed placeholder.

    The array for year should look like this:

    $array[’year’] = ’<li><span class="ditto_year">[+year+]</span>[+ditto:year+]</li>’;

    I have tried for several days to find an efficient method of doing this but have come up empty. Any help would be greatly appreciated.
      • 31337
      • 258 Posts
      Sorry, don’t understand why you need XML here You’re not dealing with structured data that requires it. Why not create the templates using <div id> to notate the placeholders?
        • 18397
        • 3,250 Posts
        Simple reason: I like <ditto:item> style tags and they make it easier to separate template item from the other HTML.
          • 25663 MODX Staff
          • 12,272 Posts
          XML is introducing a very technical topic, needless complexity, and the extra overhead of an XML parser. This doesn’t sound like a good idea at first blush...
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 18397
            • 3,250 Posts
            So, you don’t think XML Templating is a good idea. Fair enough. What do you think would work better? Should I go back to the [++subtemplate++] specification? Should I use the ETS library (masks for each subtemplate)? I am open to suggestions.
              • 25663 MODX Staff
              • 12,272 Posts
              If you meant the tiny but strong library (TBS) no. Even bS is abandoning that when the new parser comes out. He’s porting it over to "native" MODx templating.

              What’s the matter with separate chunks?
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 22303 MODX Staff
                • 10,725 Posts
                Quote from: rthrash at Aug 14, 2006, 09:53 PM

                If you meant the tiny but strong library (TBS) no. Even bS is abandoning that when the new parser comes out. He’s porting it over to "native" MODx templating.

                What’s the matter with separate chunks?

                Right, you should be able to loop through each resource you want to list, set an array of replacement vars, parse the chunk, move to the next resource, reset the replacement vars, and so on... where is the complexity starting?
                  • 18397
                  • 3,250 Posts
                  Because to format the archive you would need 6 separate chunks.

                  I was referring to the Easy Template System.
                    • 22815
                    • 1,097 Posts
                    What happened to the "define lots of chunks in one file" ideas that were spinning out of Wayfinder discussions?
                    I can’t see a real way of avoiding the multiple chunks, especially when there are conditionals; keeping them in one file would just make things tidier.
                      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!
                      • 18397
                      • 3,250 Posts
                      Thats what my idea for XML based templating was. Use XML deliminators to split up the different templates stored in one chunk, file, or variable.