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

    I’ve been getting to grips with Template Variables for a while now and am really loving them.

    I’ve come across a scenario though where I’d like to be able to add new fields of the same type when writing my page.

    The scenario is this - writing an interview/Q&A session, I’d like to be able to have two template variables - Question, and Answer (so two fields). When I get to a new question, it would be nice to be able to click a button marked something like "add new question" and be able to add two mroe fields immediately below my first question and answer and carry on like that til the end.

    Is something like this do-able in the current system?
      Notanotherdotcom Ltd

      Web | Print | Marketing
      • 6726
      • 7,075 Posts
      Most definitely doable smiley

      There are probably many ways to handle this, but I can think of 3 ways it can be done.

      First there is Aour’s snippet ListFaqFolder, never tested it but worth giving a look !

      Second, there is TVs + Ditto.
      Each Q & A would be stored in a separate document, whose templates will be linked with the Tvs : question, answer.
      Then the listing page would contain a Ditto call cycling through those Q&A’s.

      The only thing is, you won’t be able to edit them directly from the listing page as you describe but rather you’ll have to edit each Q&A document separately (I gather you want to be able to edit from the frontend, am I wrong : if so, go for FrontEndDocumentManager)

      Third, you use custom tables in the DB to store those Q&As and you set up a form with eForm and get those data in the DB thanks to eForm2db. You’ll have to set another form for editing the data too.

      Just quick ideas here, there are probably other ways like writing a snippet, but then it means coding...
        .: COO - Commerce Guys - Community Driven Innovation :.


        MODx est l'outil id
        • 23072
        • 150 Posts
        Cheers for those - some good possibilities there.

        I was wondering though if there was any way of tying something into the manager when you’re editing a page there? Has anyone tried adding more functionality in that particular way as I’d be interested to know where to start with altering the manager smiley
          Notanotherdotcom Ltd

          Web | Print | Marketing
          • 34017
          • 898 Posts
          I know this is something expression engine allows through their ’custom fields’ (template variables).

          It is a great way to give customers the ability to add new items to a table or listing without them having to edit multiple documents or getting into the code.

          How to do this:
          Option 1:
          a) create a new TV type (there is a post somewhere on how to do this with star rating).
          b) Add a ajax button to add more fields/rows.
          c) Serialize the input into the TV

          This is the easiest way I see to get this to work. Anybody else know a better way to have this using 1 TV with multiple fields (that reset at 1 field per page)
            Chuck the Trukk
            ProWebscape.com :: Nashville-WebDesign.com
            - - - - - - - -
            What are TV's? Here's some info below.
            http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
            http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
            • 23072
            • 150 Posts
            Prowebscape - that’s an excellent idea and gets around the stickiness of having to have a different document for each entry - something I really didn’t want to consider for something so trivial.

            It would be nice if you could have TV "sets" in a future version of MODx though, so the TV table (assuming TV’s are stored in a TV table?) could have many of the same TV for each document, going off the document ID, with another column in the table for a "group ID".

            So you could have "Add row" for repeating individual TV’s - group ID of -1 for the sake of argument - 0 for non-repeating ID’s and all TV’s with the same group ID greater than 0 could have an add TV set below the set to add another set of TV’s.

            Obviously that would be a bit of a change to the current system, but makes TV’s a lot more flexible without messy workarounds. Just got to find a "feature request" thread now!
              Notanotherdotcom Ltd

              Web | Print | Marketing
              • 28580
              • 24 Posts
              This is a problem I’ve been trying to find a solution to for a while. It’s not just modx but many CMS’s seem to have a blind spot when it comes to this issue which comes up in most larger CMS based projects at some point. ProWebscapes solution looks good but could anyone post any examples of how they have done this? Even better would be a plugin that allows you to check a "make repeating" box when creating a TV (and while we’re at it the ability to make a repeating group of TVs would be even better)
                • 34017
                • 898 Posts
                stev,

                i dont know if anyone else has done this. I am thinking of installing a table editor and just using jquery to popup the module for that page id. That seems like the easiest way now.

                My above idea got tougher and tougher (since i didnt want to hack the core)
                  Chuck the Trukk
                  ProWebscape.com :: Nashville-WebDesign.com
                  - - - - - - - -
                  What are TV's? Here's some info below.
                  http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
                  http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
                  • 28580
                  • 24 Posts
                  thanks for the reply. I did have one other (very hacky) idea of how to get around this. If it is possible to create separate instances of the rich text editor to add as a new input type then you could use different tinymce themes for different TVs. By adding custom buttons to the theme that handle the input values you want you could build up repeating groups. I haven’t looked into actually doing this yet as it seems like an overcomplicated solution but for some situations it may prove to be suitable. For instance if the page has an element that requires entry of one or more images then the use of tinymce locked down to just the add image button allows the images to be displayed in the manager as they are added and already handles adding links and alt text to those images.
                    • 34017
                    • 898 Posts
                    Well I’ve been working on this a little bit. And I need the each cell’s data to be extracted and massaged via php before it’s shown as output. So I’ve got a jquery function to do the following:
                    1. have a table with as many columns as you wish
                    2. An add link to add new rows
                    3. A remove link next to each row
                    4. The post results are a multi-dimensional array.

                    I am going to make this a modal/pop-up in the manager (i think an iframe would be confusing). I am not sure how I want to save the results in the db. I think a serialized record into a TV field would make it play nice with other snippets. But a seperate table might make it easier. Either way we’ll have to have a snippet to parse the results. And it’ll have a prerequisite of ManagerManager I think.

                    I am doing this so a client can have one box where they can put in multiple store options like
                    Col A | Col B | Col C |
                    Size Small 9.00
                    Size Medium 10.00
                    Size Large 11.00
                    Color Red
                    Color Blue
                    Color Green Out of Stock

                    Then I can create my snippet to do whatever I want with that array. The key is it’s really easy for the client though it’s tougher on me- but I have ultimate flexibility. This wouldn’t work with maybe a huge site, but for a small one with options, it’ll be nice I think.

                    I’m open to any ideas.
                      Chuck the Trukk
                      ProWebscape.com :: Nashville-WebDesign.com
                      - - - - - - - -
                      What are TV's? Here's some info below.
                      http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
                      http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
                      • 34017
                      • 898 Posts
                      Alright, I’m finally getting somewhere. I’ve got the all above working and added a drag-drop to the table rows. I’ve got it reading the values as well and am working on the templating aspects now.

                      The next part will be how to display the modal in the manager section, and how to save the data. If anyone has any ideas, please let me know.
                        Chuck the Trukk
                        ProWebscape.com :: Nashville-WebDesign.com
                        - - - - - - - -
                        What are TV's? Here's some info below.
                        http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
                        http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008