We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36575
    • 104 Posts
    Hi,
    I'm wondering if there is any way to do the following, either in modx or an addon/extra.
    A client has a site with various products, and the variants on them (colours/size) keep growing. Right now, I have many chunks with a different dropdown list in each one and an @EVAL binding to allow the client to select the one required. This worked fine when I had about 10 option/combinations, but now I am adding two or three variants a month and there are more than 25 items in the dropdown list - i'd like something easier to manage going forward.
    Is there any way I could create a TV that the client could add a comma delimited list of the options, and then that would create a dropdown list to be added onto the front end?
    Thanks [ed. note: rachelmarama1 last edited this post 13 years, 4 months ago.]
      • 3749
      • 24,544 Posts
      I sounds like you want a "listbox" TV (selected at the top of the Input Options tab when editing the TV).

      The client would have to use double pipes rather than commas:

      red||blue||green
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 36575
        • 104 Posts
        hi BobRay, thanks for the response, but maybe i'm missing something... I can see the Listbox (singleselect) and Listbox (Multiselect) options in the TV, but these give a dropdown list in the resource - what I am looking for is an input of text or textbox, with an output of listbox, so that in the resource itself, the client can type abc||edc||jhdf|| etc and have that turn into a listbox on the actual front end page. Any chance this is possible, or am I going to have to find someone to write me a custom TV?
          • 3749
          • 24,544 Posts
          A MIGX TV may have that option, but you don't need a custom TV, just a snippet to show it.

          Something like this:

          Use a Text tv that contains a comma-separated list (default output).

          [[ShowDropdown? &items=`[[*MyTV]]`]]


          <?php
          /* ShowDropdown snippet */
          
          $output = '<select>';
          $tpl = '    <option value="[[+item]]">[[+item]]</option>';
          
          $items = explode(',', $scriptProperties['items']);
          
          foreach ($items as $item) {
              $output .= "\n" . str_replace('[[+item]]', trim($item), $tpl);
          }
          
          $output .= "\n</select>";
          return $output;
          
          [ed. note: BobRay last edited this post 13 years, 4 months ago.]
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 36575
            • 104 Posts
            Thank you!
            This is exactly what I needed and it works perfectly.

            For anyone else reading the thread, I did have to add a *before the name of MyTV eg [[ShowDropdown? &items=`[[*MyTV]]`]]

            Again, thanks BobRay
              • 3749
              • 24,544 Posts
              Sorry, I thought of that after I posted the code, but couldn't find the post to fix it. wink

              [fixed in the code above]

                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting