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!
-
☆ 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.
Thanks, Susan! I’ll give that a go and see if I can make it work!
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.
-
☆ 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.
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 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.
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/
:-)