by
KK » Wed Apr 13, 2011 5:35 pm
Hi,
Just a little detour -
You have six images (and six associated thumbnails) named gallery_img_1, gallery_img_2, gallery_img_3, gallery_img_4, gallery_img_5 and gallery_img_6 where the names differ only in the suffixed number (1-6).
To display back the images (their paths actually), we could have simply used the standard way
- Code: Select all
<cms:show gallery_img_1 />
<cms:show gallery_img_2 />
<cms:show gallery_img_3 />
<cms:show gallery_img_4 />
<cms:show gallery_img_5 />
<cms:show gallery_img_6 />
Instead of hard coding the names of the six images, as we have done above, since the names of the images are very similar we could also write -
- Code: Select all
<cms:repeat count='6' startcount='1' >
<cms:set my_img_src="<cms:get "gallery_img_<cms:show k_count />" />" />
<cms:show my_img_src />
</cms:repeat>
In the code above, we are 'generating' the image names sequentially so that my_img_src will be 'gallery_img_1' on the first iteration and 'gallery_img_6' on the last.
Essentially we can use both the approaches. The first one is simplest but can grow unwieldy if we have a large number of images while the second one is a little complex but will require only changing the 'count' from '6' to '16' for handling 16 images instead of '6'.
As a solution to your problem (discussed in thread
viewtopic.php?f=4&t=342) where you wished for 'Dynamic number of images in a post', we had used the second approach ('repeat' with 'set').
For the current video problem that you have there is
only one editable region named 'video' so you really do not have to go through the complex way of showing it as you are doing in your code -
- Code: Select all
<cms:set my_vid_src="<cms:get "video" />" />
<cms:if "<cms:not_empty my_vid_src />" >
<div><cms:show vid /></div>
</cms:if>
You could simply use -
- Code: Select all
<cms:if "<cms:not_empty video />" >
<div><cms:show video /></div>
</cms:if>
By the way, the code you were using will work too, but you are using the wrong name <cms:show vid /> where 'vid' is nothing. It should have been <cms:show my_vid_src />.
The discussion above should also answer your second query where you want to display the video's thumbnail that you have uploaded yourself.
I assume that you are using an image type editable region for the thumbnail.
Let us say its name is 'thumb_video'.
It can very simply be displayed by using the standard way -
- Code: Select all
<img src="<cms:show thumb_video />" />
You can also combine it with the check to see if it has any value or is empty -
- Code: Select all
<cms:if "<cms:not_empty thumb_video />" >
<img src="<cms:show thumb_video />" />
</cms:if>
I think you'll see the pattern.
Do let me know if anything is unclear. Thanks.