We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22770
    • 285 Posts
    I think I have some kind of mental blockage going here, because I just don’t understand template variables. At all. I’ve read all the documentation and a whole bunch of forum posts, and I just don’t get how to do them.

    Here’s what I want to do. I want to give my contributors a simple way to add an existing image to a page. I thought that the way to do this would be to have a template variable that produces a drop-down list (or similar) showing all the images in the assets/images folder. The user could then select one and it would then display on the relevant page. Is this something I could do with TVs? If so, anyone know how I would do it?

    I know I should be able to work this out, but I just can’t work out how.

    Thanks!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      If the image will always be in the same place in the page’s template, then a TV would work very well.

      Create a new TV, with the input type "image", leave the default value empty, and select an output widget type of "image", setting any of the properties you want. Make sure to check the templates you want to have access to it in the check boxes at the bottom.

      Now, in your template or in your document content somewhere, simply put the TV tag, such as [*image*] or whatever you named it. Now, for each document using that template (remember the check boxes mentioned above) there will be an additional field, beneath the content editing field. Clicking on the button will open the Resource Browser, allowing the user to select the desired image, or upload one. The path to the image will be loaded in the field. The selected image will automatically be displayed wherever you put the TV tags.

      TVs are just an extension of the existing document variables, such as [*content*] or [*pagetitle*]. Well, they are a lot more, actually, but that’s a good place to start.
        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
        • 22770
        • 285 Posts
        Thanks, Susan! I’ll give that a go and see if I can make it work!
          • 22770
          • 285 Posts
          Just thought I’d post to say that worked fantastically (and remarkably easily). Don’t know why I couldn’t figure it out. Hopefully, it’ll be easier to figure out future TVs now.
            • 24495
            • 407 Posts
            The other way is of course using a tv with "dropdown list menu". For this put some images into assets/images/nameoffolder/. Name images whatever you want, for instance: img1.gif, img2.jpg, img3.gif ... and so on.
            Set input option values as
            Image 1==img1.gif||Image 2==img2.jpg||Image 3==img3.gif

            For "Image x" set a name you want.
            Then in your template set the image as
            <img src="[(base_url)]assets/images/nameoffolder/[*nameofyourtv*]" />

            To prevent an "empty" image set the default value to e.g. img1.gif (or whatever you want as default image). If all images have the same extension (gif or jpg) you can set the option values for the file without extension and put this into the img element in HTML source.

            With using the ShowImageTVs plugin it gives a comfortable image handling with a preview of the chosen image.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              The only problem with a dropdown list menu is that you have to edit the TV list every time you add/remove images.
                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
                • 24495
                • 407 Posts
                right, that’s a task for the admin, but it’s easier to handle for dumb clients grin And it’s a solution if the image pool is fix.

                Btw: We need a solution for editing TVs with comfort in this case ...
                  • 34017
                  • 898 Posts
                  Can you create a snippet that pulls all of the files from a directory (such as assets/images) and spits it out as ImageName==im1.jpg||ImageName==img2.jpg. Then use the @eval on the TV to load that info into your dropdown list.

                  Chuck
                    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
                    • 22770
                    • 285 Posts
                    Chuck and rasc: yeah, that seems like a possibility. I’ll give it a go, if only for practice. Should be easy enough to do, I think.
                      • 11975
                      • 2,542 Posts
                      hi

                      to create the options list from the images folder you can use the @DIRECTORY bindings

                      In the options values field: @DIRECTORY assets/images/nameoffolder/

                      :-)
                        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l