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

    is there a way to sort a resourcelist TV so that it is ordered by Title. Coz it is easier to find the resources in a large list when they are sorted in alphabetic way. Otherwise it is to difficult to find the related resource and need to long time.

    thx,
    from germany [ed. note: mopox last edited this post 11 years, 6 months ago.]
      • 38136
      • 42 Posts
      I was able to emulate the behaviour as following:

      1.) I had to switch to another TV type: Listbox (single mark)
      2.) I used the @SELECT binding as following:

      @SELECT CONCAT(`pagetitle`,' (',`id`,')') AS `p`,`id` FROM `[[+PREFIX]]site_content` WHERE `parent` IN (SELECT `id` FROM `[[+PREFIX]]site_content` WHERE `parent` = 7) AND `published`= 1 ORDER BY `pagetitle` ASC


      That was it mainely. Unfortunate this method just is listing the resources at the second level underneace 7. Any ideas to increase it for all level including the first level?

      greetings
        • 40045
        • 534 Posts
        A solution to this would be helpful for me too, it's not really nice to look through a list of over 100 resources sorted by anything (ID) that's not really sorting things =)
          • 4172
          • 5,888 Posts
          you can allways have @EVAL - binding in option-values and call your own snippets, like this:

          @EVAL $output = $modx->runSnippet('getResources',array('parents'=>'99','tpl'=>'@INLINE [[+pagetitle]]([[+id]])==[[+id]]','outputSeparator'=>'||','sortby'=>'pagetitle','sortdir'=>'ASC','limit'=>'0'));return 'choose one==||' . $output;
          [ed. note: Bruno17 last edited this post 11 years, 5 months ago.]
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 38136
            • 42 Posts
            Well that is a smart idea. But isn't that bringing a problem with the modx caching system? How to make it uncached?
              • 40045
              • 534 Posts
              @Bruno, that's quite smart =), thanks for that, will have a look if it does what I need!

              What I don't understand is that there is already a TV type "resource list" which lists all resources and there are configuration options too, why not just make one which is called "sortby" which accepts a fieldname and defaults to id, I mean there is one "filter" which I don't even needed yet...

              EDIT: ok, tried Brunos suggestion, but with no luck...I just get an Array dump into the listbox (single choice)...I added the following to the "Input Options" field:

              @EVAL $output = $modx->runSnippet('getResources',array('parents'=>'1,2,3,4,5,6,7,8,12,47','tpl'=>'@INLINE[[+pagetitle]]([[+id]])==[[+id]]','outputSeparator'=>'||','sortby'=>'pagetitle','sortdir'=>'ASC','limit'=>'0')); return 'Resource wählen==||' . $output;


              with the purpose to just list all resources =), but alphabethically... any ideas what I'm doing wrong with this?

              I'm really at war with those @BINDINGS... I gave up yesterday after 3 hours of trying to achieve, that a simple "text" TV just set's it's default value dynamically (tried with @EVERYTHING...), and it wasn't even complex...I just wanted the field to have the pagetitle of the current resource in it by default, nothing else...but no way...just gave up frustrated, seems like I'm not yet ready for @BINDINGS =) [ed. note: exside last edited this post 11 years, 5 months ago.]
              • For something like that you don't need a binding, you can just put [ [*pagetitle] ] in the default value field. Bindings are for more complicated functions. While the first link is for Evo, the principles of how Bindings work are much the same.

                http://sottwell.pogwatch.com/tv-bindings.html
                http://rtfm.modx.com/display/revolution20/Bindings [ed. note: sottwell last edited this post 11 years, 3 months ago.]
                  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
                  • 4172
                  • 5,888 Posts
                  sorry, you will need a blank between the @INLINE and the code:

                  @EVAL $output = $modx->runSnippet('getResources',array('parents'=>'1,2,3,4,5,6,7,8,12,47','tpl'=>'@INLINE [[+pagetitle]]([[+id]])==[[+id]]','outputSeparator'=>'||','sortby'=>'pagetitle','sortdir'=>'ASC','limit'=>'0')); return 'Resource wählen==||' . $output;
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 40045
                    • 534 Posts
                    @susan: =) that's exactly what I tried first, this was intuitive for me, but just didn't work^^... I wanted this in a one row text TV (like the most simple TV there is =P) but when I add [[*pagetitle]] to the default value field, it just says exactly that in the resource edit screen [[*pagetitle]] (instead of the real Text of the pagetitle)...I first thought it was because the Text TV was in a MIGX grid, but the result is the same (=not working, just displaying the tag...) when I just include that TV as a normal Template Variable...

                    @Bruno: Wow, now it works!! Great help from you, thanks! I tuned the getResources call a bit to show all of the resources:

                    @EVAL $output = $modx->runSnippet('getResources',array('parents'=>'1,2,3,4,5,6,7,8,12,47','tpl'=>'@INLINE [[+pagetitle]]([[+id]])==[[+id]]','outputSeparator'=>'||','sortby'=>'pagetitle','sortdir'=>'ASC','limit'=>'0','showUnpublished'=>'1','showHidden'=>'1','depth'=>'3')); return 'Resource wählen==||' . $output;


                    the only negative thing about this is that I have to specify at least every resource in the first level to get them all...is there a more elegant way (maybe another snippet?) to just fetch all "top"-level document IDs (direct children of the context...)?
                    • Ah. I missed the part about it being in a MIGx grid. That's another matter altogether.
                        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