We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23018
    • 353 Posts
    This is some kind of evolved chunkIf (have a look at it in the extensions section: http://modxcms.com/extras/package/69) by dflock (Duncan Lock).

    The original chunkIf snippet will have a look at a TV and depending on the fact if it is empty or not display one chunk or another. Usually you’ll be using a checkbox and if it is checked chunk #1 will appear. If not chunk #2.

    For a recent project I needed something more advanced, so I decided to create something more versatile.

    Welcome to chunkWhatever.

    chunkWhatever will return one or more chunks depending on requirements you have set inside the snippet call.

    Usage: Create a TV called "test" (use a group of radio buttons and set them to be deliminated by double pipes, ||) Then add chunkWhatever to a document. Depending on which of the radiobuttons is active (checked), you can now display a specific chunk on this page.

    [[chunkWhatever?
    &tv=`test`
    &choices=`yes::yesChunk||no::noChunk||maybe::maybeChunk`
    &debugging=`screen`
    &delimiter=`||`
    &published=`1`
    ]]


    Depending on the value(s) of the TV you can now output one or more chunks. If you are using a set of checkboxes, you can even display more that one chunk at once.

    I use this one to give my editors the power to switch certain page elements ON or OFF.

    Additional feature: "Detailed debugging"
    * chunkWhatever will tell you, if a chunk or TV doesn’t exist.
    * You can send debugging informaiton to the screen or use an html comment instead (this one needs some improvement...).


    That’s it. For more information, you should study the snippet code. It will tell you all about the parameters and the general usage.

    Disclaimer: As far as I can see this snippet works as expected. I have tested several scenarios and different TVs with and without values. It behaved very well and I’m quite pleased. However, this one is only a few hours old and still BETA. Test this one on your own risk. If you find any problem, please contact me. Either by pm or email (you will find my adress inside the source).

    Have fun,

    pepebe
      Homepage: pepebe.de | MODX snippets (and other stuff) at github: https://gist.github.com/pepebe
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You can do this with a TV using check boxes or radio buttons and having something like this in the Input Option Values
      ChunkOne=={{chunkOne}}||ChunkTwo=={{chunkTwo}}||ChunkThree=={{chunkThree}}

      Or am I missing something?
        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
        • 23018
        • 353 Posts
        YOU CAN REALLY DO THAT?

        I feel kinda stupid.

        Well, I shouldn’t be surprised. Working with MODx is like sitting in a premium roller coaster. The moment you think that you know what to expect something even more astonishing comes around.

        A zillion thanks Susan.

        I never thought about that one. Really nice.

        I will try it this weekend.

        If I can make it work, you’ll become my personal MODx saint...

        Kind regards,

        pepebe

          Homepage: pepebe.de | MODX snippets (and other stuff) at github: https://gist.github.com/pepebe
          • 28042 ☆ A M B ☆
          • 24,524 Posts
            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
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            As I mention in the sidebar block tutorial linked to, there is a disadvantage; the blocks appear in the order in which they are listed in the Input Option Values field and that order can’t be changed (without changing the TV code). But it occurred to me that ManagerManager and its jquery might be able to be used to add a drag-and-drop sorting feature to such a radio button/checkbox/select field. An interesting thought. I need to take a little time to give ManagerManager a harder look.
              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
              may be this is a good startpoint for this mm-widget:
              http://www.ryancramer.com/projects/asmselect/examples/example1.html
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 4172
                • 5,888 Posts
                ok, this can work with managermanager and asmselect so far.
                the values are saved in the right order after adding them from multiselect in sort-order.

                what will not work at the moment is reordering the original-selectbox when sorting the sort-boxes with asm. May be a bug in asmselect or I’m missing something.

                Another issue is, when editing this values the next time, modx orders the input-option values, of course, as they come from input-option-values.
                So we have to find a way to resort the values before displaying the ’sort-boxes’.

                have to have a deeper look on this.




                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 26931
                  • 2,314 Posts
                  hey Bruno smiley sounds great!
                    • 23018
                    • 353 Posts
                    @susan: I have tried would you suggested, but as far as I can see it doesn’t work as expected (MODx 1.0.2). I’m sure I have missed something a try again tomorrow. Oh, thanks for the link, I’ll study it this very weekend.

                    I have also noticed that my snippet fails to work as intended in mod 1.0.2. It wasn’t able to find the TV there (yes, Ihave dopble checked it). Very strange. In 1.0.3 it works like a charm. From what I could learn, there seems to be a problem with $modx -> getTemplateVarOutput in line 134.

                    I’ll dig into this.

                    BTW

                    I have been thinking If I could add something to the snippet so it isn’t a total waste of time.

                    What If I add some more "intelligence" to the snippet?

                    The thing that came to my mind was to add the ability to use something along the lines of

                    tvValue<=10::chunk1||tvValue>10 AND tvValue<=100:chunk2||and so on...

                    Would that be something that’s worth implementing, or this again on of those things I have missed in the manual?

                    Regards,

                    pepebe
                      Homepage: pepebe.de | MODX snippets (and other stuff) at github: https://gist.github.com/pepebe