We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13461
    • 2 Posts
    My scenario
    I have a parent document for a classroom and child documents for each pupil. Each pupil (child document) has a number of template variables using TV-based chunks (see http://wiki.modxcms.com/index.php/Create_TV-Based_Chunks). Each template variable has drop with two choices (’Has achieved award’ or ’Has not achieved award’).

    If ’Has achieved award’ is selected an image is displayed on the Pupils page whereas if ’Has not achieved award’ is selected nothing is added to the pupils page.

    My problem is I want to list the pupils and their awards in the parent document i.e. a class list. I can display the class list using Wayfinder or Ditto with no problems but cannot transfer the awards selected in the template variables of each pupil. I have tried using ’Dynamic Description’ and ’GetField’ and have had limited success. With ’Dynamic Description’ I can make the awards image transfer to the parent document but only if I manually past the images into the document content box. ’GetField’ did not transfer the image (just the text).

    Tree structure
    - Classroom
    - Pupil
    - template variable 1 (drop-down ’Has achieved award 1’ or ’Has not achieved award 1’)
    - template variable 2 (drop-down ’Has achieved award 2’ or ’Has not achieved award 2’) etc.
    - Pupil

    Any ideas guys? Anything guidance much appreciated. I’m using Evolution 1.05.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      There’s no reason why Ditto shouldn’t display the TV value for the item on the parent page. Are you using the proper tags in the Ditto tpl? [+...+] and not [*...*]?
        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
        • 13461
        • 2 Posts
        Hi Susan, thanks for your reply. It is most appreciated.

        You are right. I can add my template variables within the Ditto call. I’ve tried it like so:
        <a href="/[~[+id+]~]" class="pupil">[+longtitle+]</a> [+award_1+] [+award_2+]
        and it works to a point.

        My problem is that when using TV-based chunks (see http://wiki.modxcms.com/index.php/Create_TV-Based_Chunks) the image won’t come through, just the name of the chunk. For example the above ditto call comes through like:
        Name Award achieved Award Achieved

        I would like it to come through as:
        Name <a id="award" title="Title - some description text."><img src="path/to/image.jpg" alt="award1" /></a> <a id="award" title="Title - some description text."><img src="path/to/image.jpg" alt="award2" /></a>

        I used TV-Base chunks to give the user an easy radio button interface. Award achieved chunk would be <a id="award" title="Title - some description text."><img src="path/to/awardimage.jpg" alt="award1" /></a> and award not achieved would be <a id="award" title="Title - some description text."><img src="path/to/notachieved.jpg" alt="award1" /></a>.

        The idea being the user on the frontend can see the award if selected and hover over for a tooltip or if not selected they get a placeholder graphic which also has the tooltip (so they can preview the awards before they achieve).

        If I change the template variable to use the image widget (instead of TV-based chunks) it does work to bring the image through but if you know a way to bring through an image and a link while making it user friendly in the manager with radio buttons (TV based Chunks or a better method) that would be excellent. Basically a more elegant way than the user having to use the resource browser to insert an image.

        Hope that makes sense. Thanks again.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          I see what you mean. You could make the TV a radio button with the option values being the actual chunk tags, or even have the option values be the output you want.
            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
            • 13461
            • 2 Posts
            Cheers for the quick response.

            Using chunk tags as option values still only brought the chunk name through (and not the content within the chunk). However putting the option values in there direct has worked nicely. It also created a nice looking template variable in the pupil template giving me the image next to the radio button. This gives the user a more visual way to toggle the awards.

            Thanks for you help. Solved smiley
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              To make a radio button (or check box or select drop-down) to choose between chunks, the option values would look like this:
              option1=={{chunk1}}||option2=={{chunk2}}

              Then the radio buttons would have the label option1 and option2, with the output being the actual chunk tags, which would get processed as normal during the next pass of the parser.
                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
                • 13461
                • 2 Posts
                Thanks, that worked nicely.

                One last thing you may experience of. After creating my template variables then selecting the radio button within the template everything works. However if I make a change to the template variable the radio selection is selected for some reason meaning if a user opened the document then reserved it their selection would be lost. If I revert the change the selection reappears.

                Is there any way to make it remain selected even if the template variable is changed? Any thoughts much appreciated and I promise I’ll leave you alone then smiley
                  • 36404
                  • 307 Posts
                  hi,

                  actually, not really as changing your TV you’ve also changed its values... what i would do in this case (nasty and salvage, but it should work)

                  - look at your tv id
                  - take a page/ressource and look at its id to then set your new TV and choose a value

                  then in the prefix_site_tmplvar_contentvalues table look for the value of your tv for the that ressource, write it down somwhere, change the tv value and write down the new value (now you have both your tv values)
                  set back your tv to its previous state and do the same

                  now you have both values for your tv, the old ones and the new ones

                  here comes the nasty thing -> use sql to replace the old value by the new ones (set value = ’the new value’where tmplvarid = ’id of the tV’ and value=’the old value’)
                  do this for both new values, has graduated, hasn’t and both TVs, done...

                  well you could also go and see each ressource, loof for the tv choice, write it down, set the tv to its new state and then... with 5/10 ressource, why not but if you have a lot of ressource, let’s get salvage smiley

                  have swing
                    réfléchir avant d'agir