[TYPO3-english] random images with TS - how to prevent duplicates?

Paul Vetch paul.vetch at kcl.ac.uk
Sun Feb 27 16:11:31 CET 2011


Hi,

I'm using a TS snippet to select some images at random from DAM with 
metadata (I prefer to avoid the overhead of a plugin for something so 
simple).  This solution works fine for a single image, but if used for 
creating a block of multiple random images, then the select happens for each 
image which is displayed and as a result the same image can end up being 
displayed more than once (in this case it's quite noticeable because I'm 
only selecting from a pool of 20 images).  Here's the TS I'm using -- is 
there a way I can tweak this to prevent duplicates being selected or do I 
need to start again / use a different approach?

(the example TS here has simplified output from what I'm generating but this 
does work fine except for the duplication):

temp.imageRow = CONTENT
temp.imageRow {
  table = tx_dam
  select {
    pidInList = 80
    where = media_type = 2
    andWhere = file_path = 'fileadmin/hoa/images/feature'
    orderBy = RAND()
    max = 1
    selectFields = title, copyright, file_name, file_path
  }
  renderObj = COA
  renderObj {
    20 = TEXT
    20.field = file_path
    20.wrap = |/
    30 = TEXT
    30.field = file_name
  }
}
# Render 5 img elements in a block
lib.randomImg = COA
lib.randomImg {
10 = IMAGE
10 {
  file.import.cObject < temp.imageRow
}
20 < .10
30 < .10
40 < .10
50 < .10
}

Thanks

Paul



More information about the TYPO3-english mailing list