Design and CSS styles
Version 4.x > Design and CSS styles > Transformations for Displaying different image on page refresh View modes: 
User avatar
Member
Member
ewanm - 10/29/2009 6:26:57 AM
   
Transformations for Displaying different image on page refresh
Refer to ‘Displaying different image on page refresh’ in knowledge-base

Can anyone help with creating a transformation for the above. I have numerous images stored in a subdirectory of my content files location and require to display a different image each time the site is accessed. I have attempted to create a transformation but cannot get my head around it. Any help would be appreciated.

User avatar
Kentico Developer
Kentico Developer
kentico_martind - 11/4/2009 4:49:56 AM
   
RE:Transformations for Displaying different image on page refresh
Hello,

If you want to display only image, you can use sample code bellow:
<%# IfEmpty(Eval("NewsTeaser"), "", GetImage("NewsTeaser")) %>

Where 'NewsTeaser' is name of field of 'Upload file' field type. If you use some other field type for storing image, please let us know which one you use.

Kind Regards,
Martin Dobsicek

User avatar
Member
Member
ewanm - 11/18/2009 8:00:52 AM
   
RE:Transformations for Displaying different image on page refresh
Thanks for the reply,

I have tried what you suggested and it seems to work when I use the preview function on 'My Desk' but when I look at the 'Live Site' or go online from another machine, I always get the same image whether I leave the site and return or I refresh.

As I say, every time I refresh in preview, the image changes as required.

Ewanm

User avatar
Kentico Developer
Kentico Developer
kentico_martind - 11/24/2009 2:55:16 AM
   
RE:Transformations for Displaying different image on page refresh
Hello,

this issue may be caused by image is cached. Could you please check if you have enabled caching in properties of web part or in 'Properties' section of document (full page caching)?

Best Regards,

Martin Dobsicek

User avatar
Member
Member
ewanm - 11/24/2009 6:40:17 AM
   
RE:Transformations for Displaying different image on page refresh
I have checked both the webpart and the images and none have cache enabled. As I said earlier, in preview it works OK but when live, the same image is displayed every time I refresh the page.

Regards,

Ewanm

User avatar
Kentico Developer
Kentico Developer
kentico_martind - 12/2/2009 7:45:46 AM
   
RE:Transformations for Displaying different image on page refresh
Hi Ewanm,

Could you please confirm you have checked also that you don't use full page caching in CMSDesk -> Content -> select page with repeater in tree -> Properties -> General -> Cache' section? This settings can be also inherited from parent pages so I would recommend setting it to 'no'.

Best Regards,

Martin Dobsicek

User avatar
Member
Member
ewanm - 12/2/2009 8:57:38 AM
   
RE:Transformations for Displaying different image on page refresh
Hi Martin,

I have checked and the setting is set to no. I am confused that in preview it works as it should but in live view, the same image is displayed every refresh.

Regards,

Ewanm

User avatar
Kentico Developer
Kentico Developer
kentico_martind - 12/28/2009 4:16:44 AM
   
RE:Transformations for Displaying different image on page refresh
Hi Ewanm,

In the end I was able to reproduce the issue. On my machine it happens when I enable content caching. Could you please try to set 'Cache content (minutes)' setting in 'Settings -> Web site' section to 0 for your site (or globally)?

Alternatively you may consider using 'Random documents' web part instead.

Best Regards,

Martin Dobsicek

User avatar
Member
Member
ewanm - 1/2/2010 1:19:40 AM
   
RE:Transformations for Displaying different image on page refresh
Hi Martin,

That did the trick, working great now.

Ewanm