We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31601
    • 57 Posts
    Hey all again! This time, after some searching, I think i actually have a valid question that maybe someone can help me out with!

    I am using ditto to build a list of items based on TV’s.
    Each TV has an English and a French version.

    In my template, I’m using PHx to evaluate the matched pair of language TV’s. If one doesn’t have a value (is empty), I retrieve the other value in the output.

    There actually are situations where this will happen, where one TV is empty and the other has a value.

    So, I get the output I want, but I need to sort the list based on the actual output that is read, not by the TV value. If I do :

    &orderBy=`TVenglish ASC, TVfrench ASC`

    the items are grouped together in English and French groups. I need the entire list to be sorted based on the final output.

    Is there some value that I can set in the sort parameters that would do this?

    Final little niggling problem with a very complicated project that modX has been able to deliver with all flags flying! I can’t even get into the complexity of this thing... basically, it’s a site for a video post production company (very large) and it is bilingual with a custom built flash player.

    Any help is greatly appreciated! huh
      • 5340
      • 1,624 Posts
      Why don’t you create a custom snippet?
        • 31601
        • 57 Posts
        Quote from: Cipa at Jul 23, 2009, 08:14 AM

        Why don’t you create a custom snippet?


        I have been mulling that option over. Basically, this project has forced me into learning PHP quickly, as well as using the modX API. Not a trained and tested PHP guy, and I tend to use scripting languages as I need them, so I don’t have a solid foundation in PHP.

        I was thinking of this, general idea:
        1. template ditto output into a modx placeholder array, creating a value for each array element that is the first letter of each value that ditto returns.
        2. set this new value to lower case.
        3. Sort the array by the new first letter value.
        4. Output each array element with the output template I need.


        I was also wondering if I could create a ditto extender? I just can’t seem to find any tutorials or help on extenders..

        Any other suggestions?

          • 5340
          • 1,624 Posts
          Quote from: virgil at Jul 23, 2009, 08:25 AM

          I was thinking of this, general idea:
          1. template ditto output into a modx placeholder array, creating a value for each array element that is the first letter of each value that ditto returns.
          2. set this new value to lower case.
          3. Sort the array by the new first letter value.
          4. Output each array element with the output template I need.

          That’s how I do it. I basically create my own arrays from sql, sort them, and out put them.

          I usually go like this:

          1. select what I need with an sql query
          2. loop through the sql and create my arrays(ussualy multi level arrays)
          3. Sort array on some key or value
          4. Output the array.

          Your solution might be different.

          Quote from: virgil at Jul 23, 2009, 08:25 AM

          Quote from: Cipa at Jul 23, 2009, 08:14 AM

          Why don’t you create a custom snippet?

          I was also wondering if I could create a ditto extender? I just can’t seem to find any tutorials or help on extenders..

          Last time I created an extender was by modifying one of the default extenders.
            • 31601
            • 57 Posts
            I’d love to go through the whole db and do my own sort, etc, but at this point I don’t have time to learn enough about db queries to get the solution out.

            I’m trying to do this:

            run ditto, with the save option so it will set a placeholder for me.
            read the array that ditto created and sort it myself.
            output the array in the format I need (which is for an xml feed).

            I’m really getting stuck on how to save the array, though.

            EDIT: OK, I"m able to at least get an object to be an array that has been generated by Ditto.
            BIG QUESTION: how is the array indexed? I imagine I need to create my own index value in the template I use, right?

            Basically, I have no idea how to access each element of the array that ditto has created.
              • 5340
              • 1,624 Posts
              use var_dump($array) or print_r($array).

              See what info you need extract it arrange it and use it
                • 31601
                • 57 Posts
                Well, solved this one on my own!

                Basically, I didn’t want to duplicate all the work ditto already did for me in such a nice fashion- I just wanted to sort the ditto output, not having to go through it’s entire array and do my own compares and filtering, etc. That’s been done, this shouldn’t be that complicated!

                To do this:

                1. Made a custom template for ditto that would create a long string with two values separated by special character strings. As well, since I only had two values, I used a different character string to separate the multiple values that ditto produced.

                2. In a new snippet, called ditto using custom templates and piped the output as a long string into a variable.

                3. Used the PHP explode function on the variable containing the string create an array for each pair of values.

                4. Used PHP natcasesort on the resulting array.

                5. Since I didn’t have a large set of of values, I ran a foreach loop on the resulting array and on each iteration of the loop, split the string on my inner set of special characters, echoing each line out in the format I wanted.

                So, thanks for all the help everybody- I just thought "heck, ditto did all that database work for me, I just need to sort the output as I want!"